blob: a6a0b74743aaa315fa03c8cc8df3502abb7e3dac [file] [log] [blame]
Richard Trieue7f7ed22017-02-22 01:11:25 +00001// Clear and create directories
2// RUN: rm -rf %t
3// RUN: mkdir %t
4// RUN: mkdir %t/cache
5// RUN: mkdir %t/Inputs
6
7// Build first header file
8// RUN: echo "#define FIRST" >> %t/Inputs/first.h
9// RUN: cat %s >> %t/Inputs/first.h
10
11// Build second header file
12// RUN: echo "#define SECOND" >> %t/Inputs/second.h
13// RUN: cat %s >> %t/Inputs/second.h
14
15// Build module map file
16// RUN: echo "module FirstModule {" >> %t/Inputs/module.map
17// RUN: echo " header \"first.h\"" >> %t/Inputs/module.map
18// RUN: echo "}" >> %t/Inputs/module.map
19// RUN: echo "module SecondModule {" >> %t/Inputs/module.map
20// RUN: echo " header \"second.h\"" >> %t/Inputs/module.map
21// RUN: echo "}" >> %t/Inputs/module.map
22
23// Run test
Richard Trieu639d7b62017-02-22 22:22:42 +000024// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z
Richard Trieue7f7ed22017-02-22 01:11:25 +000025
26#if !defined(FIRST) && !defined(SECOND)
27#include "first.h"
28#include "second.h"
29#endif
30
31namespace AccessSpecifiers {
32#if defined(FIRST)
33struct S1 {
34};
35#elif defined(SECOND)
36struct S1 {
37 private:
38};
39#else
40S1 s1;
41// expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
42// expected-note@first.h:* {{but in 'FirstModule' found end of class}}
43#endif
44
45#if defined(FIRST)
46struct S2 {
47 public:
48};
49#elif defined(SECOND)
50struct S2 {
51 protected:
52};
53#else
54S2 s2;
55// expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}}
56// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
57#endif
58} // namespace AccessSpecifiers
59
Richard Trieu639d7b62017-02-22 22:22:42 +000060namespace StaticAssert {
61#if defined(FIRST)
62struct S1 {
63 static_assert(1 == 1, "First");
64};
65#elif defined(SECOND)
66struct S1 {
67 static_assert(1 == 1, "Second");
68};
69#else
70S1 s1;
71// expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}}
72// expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}}
73#endif
74
75#if defined(FIRST)
76struct S2 {
77 static_assert(2 == 2, "Message");
78};
79#elif defined(SECOND)
80struct S2 {
81 static_assert(2 == 2);
82};
83#else
84S2 s2;
85// expected-error@second.h:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}}
86// expected-note@first.h:* {{but in 'FirstModule' found static assert with message}}
87#endif
88
89#if defined(FIRST)
90struct S3 {
91 static_assert(3 == 3, "Message");
92};
93#elif defined(SECOND)
94struct S3 {
95 static_assert(3 != 4, "Message");
96};
97#else
98S3 s3;
99// expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}}
100// expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}}
101#endif
102
103#if defined(FIRST)
104struct S4 {
105 static_assert(4 == 4, "Message");
106};
107#elif defined(SECOND)
108struct S4 {
109 public:
110};
111#else
112S4 s4;
113// expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
114// expected-note@first.h:* {{but in 'FirstModule' found static assert}}
115#endif
116}
117
Richard Trieud0786092017-02-23 00:23:01 +0000118namespace Field {
119#if defined(FIRST)
120struct S1 {
121 int x;
122 private:
123 int y;
124};
125#elif defined(SECOND)
126struct S1 {
127 int x;
128 int y;
129};
130#else
131S1 s1;
132// expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
133// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
134#endif
135
136#if defined(FIRST)
137struct S2 {
138 int x;
139 int y;
140};
141#elif defined(SECOND)
142struct S2 {
143 int y;
144 int x;
145};
146#else
147S2 s2;
148// expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
149// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
150#endif
Richard Trieubcaaf962017-02-23 03:25:57 +0000151
152#if defined(FIRST)
153struct S3 {
154 double x;
155};
156#elif defined(SECOND)
157struct S3 {
158 int x;
159};
160#else
161S3 s3;
162// expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}}
163// expected-note@second.h:* {{declaration of 'x' does not match}}
164#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000165
166#if defined(FIRST)
167typedef int A;
168struct S4 {
169 A x;
170};
171
172struct S5 {
173 A x;
174};
175#elif defined(SECOND)
176typedef int B;
177struct S4 {
178 B x;
179};
180
181struct S5 {
182 int x;
183};
184#else
185S4 s4;
Alex Lorenz76377dc2017-03-10 15:04:58 +0000186// expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'Field::B' (aka 'int')}}
187// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000188
189S5 s5;
190// expected-error@second.h:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}}
Alex Lorenz76377dc2017-03-10 15:04:58 +0000191// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000192#endif
193
Richard Trieu93772fc2017-02-24 20:59:28 +0000194#if defined(FIRST)
195struct S6 {
196 unsigned x;
197};
198#elif defined(SECOND)
199struct S6 {
200 unsigned x : 1;
201};
202#else
203S6 s6;
204// expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}}
205// expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}}
206#endif
207
208#if defined(FIRST)
209struct S7 {
210 unsigned x : 2;
211};
212#elif defined(SECOND)
213struct S7 {
214 unsigned x : 1;
215};
216#else
217S7 s7;
218// expected-error@second.h:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}}
219// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
220#endif
221
222#if defined(FIRST)
223struct S8 {
224 unsigned x : 2;
225};
226#elif defined(SECOND)
227struct S8 {
228 unsigned x : 1 + 1;
229};
230#else
231S8 s8;
232// expected-error@second.h:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}}
233// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
234#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000235
Richard Trieu8d543e22017-02-24 23:35:37 +0000236#if defined(FIRST)
237struct S9 {
238 mutable int x;
239};
240#elif defined(SECOND)
241struct S9 {
242 int x;
243};
244#else
245S9 s9;
246// expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
247// expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}}
248#endif
249
250#if defined(FIRST)
251struct S10 {
252 unsigned x = 5;
253};
254#elif defined(SECOND)
255struct S10 {
256 unsigned x;
257};
258#else
259S10 s10;
260// expected-error@second.h:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initalizer}}
261// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}}
262#endif
263
264#if defined(FIRST)
265struct S11 {
266 unsigned x = 5;
267};
268#elif defined(SECOND)
269struct S11 {
270 unsigned x = 7;
271};
272#else
273S11 s11;
274// expected-error@second.h:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}}
275// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
276#endif
277
Richard Trieu02552272017-05-02 23:58:52 +0000278#if defined(FIRST)
279struct S12 {
280 unsigned x[5];
281};
282#elif defined(SECOND)
283struct S12 {
284 unsigned x[7];
285};
286#else
287S12 s12;
288// expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}}
289// expected-note@second.h:* {{declaration of 'x' does not match}}
290#endif
291
292#if defined(FIRST)
293struct S13 {
294 unsigned x[7];
295};
296#elif defined(SECOND)
297struct S13 {
298 double x[7];
299};
300#else
301S13 s13;
302// expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}}
303// expected-note@second.h:* {{declaration of 'x' does not match}}
304#endif
Richard Trieud0786092017-02-23 00:23:01 +0000305} // namespace Field
306
Richard Trieu48143742017-02-28 21:24:38 +0000307namespace Method {
308#if defined(FIRST)
309struct S1 {
310 void A() {}
311};
312#elif defined(SECOND)
313struct S1 {
314 private:
315 void A() {}
316};
317#else
318S1 s1;
319// expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
320// expected-note@first.h:* {{but in 'FirstModule' found method}}
321#endif
322
323#if defined(FIRST)
324struct S2 {
325 void A() {}
326 void B() {}
327};
328#elif defined(SECOND)
329struct S2 {
330 void B() {}
331 void A() {}
332};
333#else
334S2 s2;
335// expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
336// expected-note@first.h:* {{but in 'FirstModule' found method 'A'}}
337#endif
Richard Trieu583e2c12017-03-04 00:08:58 +0000338
339#if defined(FIRST)
340struct S3 {
341 static void A() {}
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000342 void A(int) {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000343};
344#elif defined(SECOND)
345struct S3 {
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000346 void A(int) {}
347 static void A() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000348};
349#else
350S3 s3;
351// expected-error@second.h:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}}
352// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}}
353#endif
354
355#if defined(FIRST)
356struct S4 {
357 virtual void A() {}
358 void B() {}
359};
360#elif defined(SECOND)
361struct S4 {
362 void A() {}
363 virtual void B() {}
364};
365#else
366S4 s4;
367// expected-error@second.h:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}}
368// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}}
369#endif
370
371#if defined(FIRST)
372struct S5 {
373 virtual void A() = 0;
374 virtual void B() {};
375};
376#elif defined(SECOND)
377struct S5 {
378 virtual void A() {}
379 virtual void B() = 0;
380};
381#else
382S5 *s5;
383// expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
384// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}}
385#endif
386
387#if defined(FIRST)
388struct S6 {
389 inline void A() {}
390};
391#elif defined(SECOND)
392struct S6 {
393 void A() {}
394};
395#else
396S6 s6;
397// expected-error@second.h:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}}
398// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}}
399#endif
400
401#if defined(FIRST)
402struct S7 {
403 void A() volatile {}
404 void A() {}
405};
406#elif defined(SECOND)
407struct S7 {
408 void A() {}
409 void A() volatile {}
410};
411#else
412S7 s7;
413// expected-error@second.h:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}}
414// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}}
415#endif
416
417#if defined(FIRST)
418struct S8 {
419 void A() const {}
420 void A() {}
421};
422#elif defined(SECOND)
423struct S8 {
424 void A() {}
425 void A() const {}
426};
427#else
428S8 s8;
429// expected-error@second.h:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}}
430// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}}
431#endif
432
Richard Trieu02552272017-05-02 23:58:52 +0000433#if defined(FIRST)
434struct S9 {
435 void A(int x) {}
436 void A(int x, int y) {}
437};
438#elif defined(SECOND)
439struct S9 {
440 void A(int x, int y) {}
441 void A(int x) {}
442};
443#else
444S9 s9;
445// expected-error@second.h:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}}
446// expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}}
447#endif
448
449#if defined(FIRST)
450struct S10 {
451 void A(int x) {}
452 void A(float x) {}
453};
454#elif defined(SECOND)
455struct S10 {
456 void A(float x) {}
457 void A(int x) {}
458};
459#else
460S10 s10;
461// expected-error@second.h:* {{'Method::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'float'}}
462// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}}
463#endif
464
465#if defined(FIRST)
466struct S11 {
467 void A(int x) {}
468};
469#elif defined(SECOND)
470struct S11 {
471 void A(int y) {}
472};
473#else
474S11 s11;
475// expected-error@second.h:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}}
476// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}}
477#endif
478
479#if defined(FIRST)
480struct S12 {
481 void A(int x) {}
482};
483#elif defined(SECOND)
484struct S12 {
485 void A(int x = 1) {}
486};
487#else
488S12 s12;
489// TODO: This should produce an error.
490#endif
491
492#if defined(FIRST)
493struct S13 {
494 void A(int x = 1 + 0) {}
495};
496#elif defined(SECOND)
497struct S13 {
498 void A(int x = 1) {}
499};
500#else
501S13 s13;
502// TODO: This should produce an error.
503#endif
504
505#if defined(FIRST)
506struct S14 {
507 void A(int x[2]) {}
508};
509#elif defined(SECOND)
510struct S14 {
511 void A(int x[3]) {}
512};
513#else
514S14 s14;
515// expected-error@second.h:* {{'Method::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [3]'}}
516// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}}
517#endif
Richard Trieu48143742017-02-28 21:24:38 +0000518} // namespace Method
519
Richard Trieue7f7ed22017-02-22 01:11:25 +0000520// Naive parsing of AST can lead to cycles in processing. Ensure
521// self-references don't trigger an endless cycles of AST node processing.
522namespace SelfReference {
523#if defined(FIRST)
524template <template <int> class T> class Wrapper {};
525
526template <int N> class S {
527 S(Wrapper<::SelfReference::S> &Ref) {}
528};
529
530struct Xx {
531 struct Yy {
532 };
533};
534
535Xx::Xx::Xx::Yy yy;
536
537namespace NNS {
538template <typename> struct Foo;
539template <template <class> class T = NNS::Foo>
540struct NestedNamespaceSpecifier {};
541}
542#endif
543} // namespace SelfReference
544
Richard Trieu33562c22017-03-08 00:13:19 +0000545namespace TypeDef {
546#if defined(FIRST)
547struct S1 {
548 typedef int a;
549};
550#elif defined(SECOND)
551struct S1 {
552 typedef double a;
553};
554#else
555S1 s1;
556// expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
557// expected-note@second.h:* {{declaration of 'a' does not match}}
558#endif
559
560#if defined(FIRST)
561struct S2 {
562 typedef int a;
563};
564#elif defined(SECOND)
565struct S2 {
566 typedef int b;
567};
568#else
569S2 s2;
570// expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
571// expected-note@second.h:* {{definition has no member 'a'}}
572#endif
573
574#if defined(FIRST)
575typedef int T;
576struct S3 {
577 typedef T a;
578};
579#elif defined(SECOND)
580typedef double T;
581struct S3 {
582 typedef T a;
583};
584#else
585S3 s3;
586// expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
587// expected-note@second.h:* {{declaration of 'a' does not match}}
588#endif
589} // namespace TypeDef
590
591namespace Using {
592#if defined(FIRST)
593struct S1 {
594 using a = int;
595};
596#elif defined(SECOND)
597struct S1 {
598 using a = double;
599};
600#else
601S1 s1;
602// expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
603// expected-note@second.h:* {{declaration of 'a' does not match}}
604#endif
605
606#if defined(FIRST)
607struct S2 {
608 using a = int;
609};
610#elif defined(SECOND)
611struct S2 {
612 using b = int;
613};
614#else
615S2 s2;
616// expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
617// expected-note@second.h:* {{definition has no member 'a'}}
618#endif
619
620#if defined(FIRST)
621typedef int T;
622struct S3 {
623 using a = T;
624};
625#elif defined(SECOND)
626typedef double T;
627struct S3 {
628 using a = T;
629};
630#else
631S3 s3;
632// expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
633// expected-note@second.h:* {{declaration of 'a' does not match}}
634#endif
635} // namespace Using
636
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000637namespace RecordType {
638#if defined(FIRST)
639struct B1 {};
640struct S1 {
641 B1 x;
642};
643#elif defined(SECOND)
644struct A1 {};
645struct S1 {
646 A1 x;
647};
648#else
649S1 s1;
650// expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
651// expected-note@second.h:* {{declaration of 'x' does not match}}
652#endif
653}
654
655namespace DependentType {
656#if defined(FIRST)
657template <class T>
658class S1 {
659 typename T::typeA x;
660};
661#elif defined(SECOND)
662template <class T>
663class S1 {
664 typename T::typeB x;
665};
666#else
667template<class T>
668using U1 = S1<T>;
669// expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
670// expected-note@second.h:* {{declaration of 'x' does not match}}
671#endif
672}
673
674namespace ElaboratedType {
675#if defined(FIRST)
676namespace N1 { using type = double; }
677struct S1 {
678 N1::type x;
679};
680#elif defined(SECOND)
681namespace N1 { using type = int; }
682struct S1 {
683 N1::type x;
684};
685#else
686S1 s1;
687// expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}}
688// expected-note@second.h:* {{declaration of 'x' does not match}}
689#endif
690}
691
692namespace Enum {
693#if defined(FIRST)
694enum A1 {};
695struct S1 {
696 A1 x;
697};
698#elif defined(SECOND)
699enum A2 {};
700struct S1 {
701 A2 x;
702};
703#else
704S1 s1;
705// expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
706// expected-note@second.h:* {{declaration of 'x' does not match}}
707#endif
708}
Hans Wennborg22707762017-04-12 16:40:26 +0000709
Richard Trieuce81b192017-05-17 03:23:35 +0000710namespace NestedNamespaceSpecifier {
711#if defined(FIRST)
712namespace LevelA1 {
713using Type = int;
714}
715
716struct S1 {
717 LevelA1::Type x;
718};
719# elif defined(SECOND)
720namespace LevelB1 {
721namespace LevelC1 {
722using Type = int;
723}
724}
725
726struct S1 {
727 LevelB1::LevelC1::Type x;
728};
729#else
730S1 s1;
731// expected-error@second.h:* {{'NestedNamespaceSpecifier::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB1::LevelC1::Type' (aka 'int')}}
732// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
733#endif
734
735#if defined(FIRST)
736namespace LevelA2 { using Type = int; }
737struct S2 {
738 LevelA2::Type x;
739};
740# elif defined(SECOND)
741struct S2 {
742 int x;
743};
744#else
745S2 s2;
746// expected-error@second.h:* {{'NestedNamespaceSpecifier::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}}
747// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
748#endif
749
750namespace LevelA3 { using Type = int; }
751namespace LevelB3 { using Type = int; }
752#if defined(FIRST)
753struct S3 {
754 LevelA3::Type x;
755};
756# elif defined(SECOND)
757struct S3 {
758 LevelB3::Type x;
759};
760#else
761S3 s3;
762// expected-error@second.h:* {{'NestedNamespaceSpecifier::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB3::Type' (aka 'int')}}
763// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
764#endif
765
766#if defined(FIRST)
767struct TA4 { using Type = int; };
768struct S4 {
769 TA4::Type x;
770};
771# elif defined(SECOND)
772struct TB4 { using Type = int; };
773struct S4 {
774 TB4::Type x;
775};
776#else
777S4 s4;
778// expected-error@second.h:* {{'NestedNamespaceSpecifier::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'TB4::Type' (aka 'int')}}
779// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
780#endif
781
782#if defined(FIRST)
783struct T5 { using Type = int; };
784struct S5 {
785 T5::Type x;
786};
787# elif defined(SECOND)
788namespace T5 { using Type = int; };
789struct S5 {
790 T5::Type x;
791};
792#else
793S5 s5;
794// expected-error@second.h:* {{'NestedNamespaceSpecifier::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'T5::Type' (aka 'int')}}
795// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
796#endif
797
798#if defined(FIRST)
799namespace N6 {using I = int;}
800struct S6 {
801 NestedNamespaceSpecifier::N6::I x;
802};
803# elif defined(SECOND)
804using I = int;
805struct S6 {
806 ::NestedNamespaceSpecifier::I x;
807};
808#else
809S6 s6;
810// expected-error@second.h:* {{'NestedNamespaceSpecifier::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '::NestedNamespaceSpecifier::I' (aka 'int')}}
811// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
812#endif
813
814#if defined(FIRST)
815template <class T, class U>
816class S7 {
817 typename T::type *x = {};
818 int z = x->T::foo();
819};
820#elif defined(SECOND)
821template <class T, class U>
822class S7 {
823 typename T::type *x = {};
824 int z = x->U::foo();
825};
826#else
827template <class T, class U>
828using U7 = S7<T, U>;
829// expected-error@second.h:* {{'NestedNamespaceSpecifier::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'z' with an initializer}}
830// expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}}
831#endif
832
833#if defined(FIRST)
834template <class T>
835class S8 {
836 int x = T::template X<int>::value;
837};
838#elif defined(SECOND)
839template <class T>
840class S8 {
841 int x = T::template Y<int>::value;
842};
843#else
844template <class T>
845using U8 = S8<T>;
846// expected-error@second.h:* {{'NestedNamespaceSpecifier::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}}
847// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
848#endif
849
850#if defined(FIRST)
851namespace N9 { using I = int; }
852namespace O9 = N9;
853struct S9 {
854 O9::I x;
855};
856#elif defined(SECOND)
857namespace N9 { using I = int; }
858namespace P9 = N9;
859struct S9 {
860 P9::I x;
861};
862#else
863S9 s9;
864// expected-error@second.h:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}}
865// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
866#endif
867}
868
Richard Trieu96b49622017-05-31 00:31:58 +0000869namespace TemplateSpecializationType {
870#if defined(FIRST)
871template <class T1> struct U1 {};
872struct S1 {
873 U1<int> u;
874};
875#elif defined(SECOND)
876template <class T1, class T2> struct U1 {};
877struct S1 {
878 U1<int, int> u;
879};
880#else
881S1 s1;
882// expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}}
883// expected-note@second.h:* {{declaration of 'u' does not match}}
884#endif
885
886#if defined(FIRST)
887template <class T1> struct U2 {};
888struct S2 {
889 U2<int> u;
890};
891#elif defined(SECOND)
892template <class T1> struct V1 {};
893struct S2 {
894 V1<int> u;
895};
896#else
897S2 s2;
898// expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}}
899// expected-note@second.h:* {{declaration of 'u' does not match}}
900#endif
901}
902
Richard Trieue7f7ed22017-02-22 01:11:25 +0000903// Interesting cases that should not cause errors. struct S should not error
904// while struct T should error at the access specifier mismatch at the end.
905namespace AllDecls {
Richard Trieu02552272017-05-02 23:58:52 +0000906#define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \
907 typedef int INT; \
908 struct NAME { \
909 public: \
910 private: \
911 protected: \
912 static_assert(1 == 1, "Message"); \
913 static_assert(2 == 2); \
914 \
915 int x; \
916 double y; \
917 \
918 INT z; \
919 \
920 unsigned a : 1; \
921 unsigned b : 2 * 2 + 5 / 2; \
922 \
923 mutable int c = sizeof(x + y); \
924 \
925 void method() {} \
926 static void static_method() {} \
927 virtual void virtual_method() {} \
928 virtual void pure_virtual_method() = 0; \
929 inline void inline_method() {} \
930 void volatile_method() volatile {} \
931 void const_method() const {} \
932 \
933 typedef int typedef_int; \
934 using using_int = int; \
935 \
936 void method_one_arg(int x) {} \
937 void method_one_arg_default_argument(int x = 5 + 5) {} \
938 void method_decayed_type(int x[5]) {} \
939 \
940 int constant_arr[5]; \
941 \
942 ACCESS: \
Richard Trieufe564052017-04-20 02:53:53 +0000943 };
944
Richard Trieue7f7ed22017-02-22 01:11:25 +0000945#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000946CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000947#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000948CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000949#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000950S *s;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000951#endif
952
953#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000954CREATE_ALL_DECL_STRUCT(T, private)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000955#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000956CREATE_ALL_DECL_STRUCT(T, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000957#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000958T *t;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000959// expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
960// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
961#endif
962}
963
964namespace FriendFunction {
965#if defined(FIRST)
966void F(int = 0);
967struct S { friend void F(int); };
968#elif defined(SECOND)
969void F(int);
970struct S { friend void F(int); };
971#else
972S s;
973#endif
974
975#if defined(FIRST)
976void G(int = 0);
977struct T {
978 friend void G(int);
979
980 private:
981};
982#elif defined(SECOND)
983void G(int);
984struct T {
985 friend void G(int);
986
987 public:
988};
989#else
990T t;
991// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
992// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
993#endif
994} // namespace FriendFunction
995
996namespace ImplicitDecl {
997#if defined(FIRST)
998struct S { };
999void S_Constructors() {
1000 // Trigger creation of implicit contructors
1001 S foo;
1002 S bar = foo;
1003 S baz(bar);
1004}
1005#elif defined(SECOND)
1006struct S { };
1007#else
1008S s;
1009#endif
1010
1011#if defined(FIRST)
1012struct T {
1013 private:
1014};
1015void T_Constructors() {
1016 // Trigger creation of implicit contructors
1017 T foo;
1018 T bar = foo;
1019 T baz(bar);
1020}
1021#elif defined(SECOND)
1022struct T {
1023 public:
1024};
1025#else
1026T t;
1027// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
1028// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
1029#endif
1030
1031} // namespace ImplicitDelc
1032
1033namespace TemplatedClass {
1034#if defined(FIRST)
1035template <class>
1036struct S {};
1037#elif defined(SECOND)
1038template <class>
1039struct S {};
1040#else
1041S<int> s;
1042#endif
1043
1044#if defined(FIRST)
1045template <class>
1046struct T {
1047 private:
1048};
1049#elif defined(SECOND)
1050template <class>
1051struct T {
1052 public:
1053};
1054#else
1055T<int> t;
1056// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
1057// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
1058#endif
1059} // namespace TemplatedClass
1060
1061namespace TemplateClassWithField {
1062#if defined(FIRST)
1063template <class A>
1064struct S {
1065 A a;
1066};
1067#elif defined(SECOND)
1068template <class A>
1069struct S {
1070 A a;
1071};
1072#else
1073S<int> s;
1074#endif
1075
1076#if defined(FIRST)
1077template <class A>
1078struct T {
1079 A a;
1080
1081 private:
1082};
1083#elif defined(SECOND)
1084template <class A>
1085struct T {
1086 A a;
1087
1088 public:
1089};
1090#else
1091T<int> t;
1092// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
1093// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
1094#endif
1095} // namespace TemplateClassWithField
1096
1097namespace TemplateClassWithTemplateField {
1098#if defined(FIRST)
1099template <class A>
1100class WrapperS;
1101template <class A>
1102struct S {
1103 WrapperS<A> a;
1104};
1105#elif defined(SECOND)
1106template <class A>
1107class WrapperS;
1108template <class A>
1109struct S {
1110 WrapperS<A> a;
1111};
1112#else
1113template <class A>
1114class WrapperS{};
1115S<int> s;
1116#endif
1117
1118#if defined(FIRST)
1119template <class A>
1120class WrapperT;
1121template <class A>
1122struct T {
1123 WrapperT<A> a;
1124
1125 public:
1126};
1127#elif defined(SECOND)
1128template <class A>
1129class WrapperT;
1130template <class A>
1131struct T {
1132 WrapperT<A> a;
1133
1134 private:
1135};
1136#else
1137template <class A>
1138class WrapperT{};
1139T<int> t;
1140// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1141// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1142#endif
1143} // namespace TemplateClassWithTemplateField
1144
1145namespace EnumWithForwardDeclaration {
1146#if defined(FIRST)
1147enum E : int;
1148struct S {
1149 void get(E) {}
1150};
1151#elif defined(SECOND)
1152enum E : int { A, B };
1153struct S {
1154 void get(E) {}
1155};
1156#else
1157S s;
1158#endif
1159
1160#if defined(FIRST)
1161struct T {
1162 void get(E) {}
1163 public:
1164};
1165#elif defined(SECOND)
1166struct T {
1167 void get(E) {}
1168 private:
1169};
1170#else
1171T t;
1172// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1173// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1174#endif
1175} // namespace EnumWithForwardDeclaration
1176
1177namespace StructWithForwardDeclaration {
1178#if defined(FIRST)
1179struct P {};
1180struct S {
1181 struct P *ptr;
1182};
1183#elif defined(SECOND)
1184struct S {
1185 struct P *ptr;
1186};
1187#else
1188S s;
1189#endif
1190
1191#if defined(FIRST)
1192struct Q {};
1193struct T {
1194 struct Q *ptr;
1195 public:
1196};
1197#elif defined(SECOND)
1198struct T {
1199 struct Q *ptr;
1200 private:
1201};
1202#else
1203T t;
1204// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1205// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1206#endif
1207} // namespace StructWithForwardDeclaration
1208
1209namespace StructWithForwardDeclarationNoDefinition {
1210#if defined(FIRST)
1211struct P;
1212struct S {
1213 struct P *ptr;
1214};
1215#elif defined(SECOND)
1216struct S {
1217 struct P *ptr;
1218};
1219#else
1220S s;
1221#endif
1222
1223#if defined(FIRST)
1224struct Q;
1225struct T {
1226 struct Q *ptr;
1227
1228 public:
1229};
1230#elif defined(SECOND)
1231struct T {
1232 struct Q *ptr;
1233
1234 private:
1235};
1236#else
1237T t;
1238// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1239// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1240#endif
1241} // namespace StructWithForwardDeclarationNoDefinition
1242
Richard Trieufe564052017-04-20 02:53:53 +00001243namespace LateParsedDefaultArgument {
1244#if defined(FIRST)
1245template <typename T>
1246struct S {
1247 struct R {
1248 void foo(T x = 0) {}
1249 };
1250};
1251#elif defined(SECOND)
1252#else
1253void run() {
1254 S<int>::R().foo();
1255}
1256#endif
1257}
1258
1259namespace LateParsedDefaultArgument {
1260#if defined(FIRST)
1261template <typename alpha> struct Bravo {
1262 void charlie(bool delta = false) {}
1263};
1264typedef Bravo<char> echo;
1265echo foxtrot;
1266
1267Bravo<char> golf;
1268#elif defined(SECOND)
1269#else
1270#endif
1271}
1272
Richard Trieu157ed942017-04-28 22:03:28 +00001273namespace DifferentParameterNameInTemplate {
1274#if defined(FIRST) || defined(SECOND)
1275template <typename T>
1276struct S {
1277 typedef T Type;
1278
1279 static void Run(const Type *name_one);
1280};
1281
1282template <typename T>
1283void S<T>::Run(const T *name_two) {}
1284
1285template <typename T>
1286struct Foo {
1287 ~Foo() { Handler::Run(nullptr); }
1288 Foo() {}
1289
1290 class Handler : public S<T> {};
1291
1292 void Get(typename Handler::Type *x = nullptr) {}
1293 void Add() { Handler::Run(nullptr); }
1294};
1295#endif
1296
1297#if defined(FIRST)
1298struct Beta;
1299
1300struct Alpha {
1301 Alpha();
1302 void Go() { betas.Get(); }
1303 Foo<Beta> betas;
1304};
1305
1306#elif defined(SECOND)
1307struct Beta {};
1308
1309struct BetaHelper {
1310 void add_Beta() { betas.Add(); }
1311 Foo<Beta> betas;
1312};
1313
1314#else
1315Alpha::Alpha() {}
1316#endif
1317}
1318
Richard Trieu02552272017-05-02 23:58:52 +00001319namespace ParameterTest {
1320#if defined(FIRST)
1321class X {};
1322template <typename G>
1323class S {
1324 public:
1325 typedef G Type;
1326 static inline G *Foo(const G *a, int * = nullptr);
1327};
1328
1329template<typename G>
1330G* S<G>::Foo(const G* aaaa, int*) {}
1331#elif defined(SECOND)
1332template <typename G>
1333class S {
1334 public:
1335 typedef G Type;
1336 static inline G *Foo(const G *a, int * = nullptr);
1337};
1338
1339template<typename G>
1340G* S<G>::Foo(const G* asdf, int*) {}
1341#else
1342S<X> s;
1343#endif
1344}
1345
Richard Trieub35ef2a2017-05-09 03:24:34 +00001346namespace MultipleTypedefs {
1347#if defined(FIRST)
1348typedef int B1;
1349typedef B1 A1;
1350struct S1 {
1351 A1 x;
1352};
1353#elif defined(SECOND)
1354typedef int A1;
1355struct S1 {
1356 A1 x;
1357};
1358#else
1359S1 s1;
1360#endif
1361
1362#if defined(FIRST)
1363struct T2 { int x; };
1364typedef T2 B2;
1365typedef B2 A2;
1366struct S2 {
1367 T2 x;
1368};
1369#elif defined(SECOND)
1370struct T2 { int x; };
1371typedef T2 A2;
1372struct S2 {
1373 T2 x;
1374};
1375#else
1376S2 s2;
1377#endif
1378}
Richard Trieu02552272017-05-02 23:58:52 +00001379
Richard Trieue7f7ed22017-02-22 01:11:25 +00001380// Keep macros contained to one file.
1381#ifdef FIRST
1382#undef FIRST
1383#endif
1384#ifdef SECOND
1385#undef SECOND
1386#endif