blob: 947583bcfd216712fb91d6611a2a56228fa4b347 [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 Trieue7f7ed22017-02-22 01:11:25 +0000869// Interesting cases that should not cause errors. struct S should not error
870// while struct T should error at the access specifier mismatch at the end.
871namespace AllDecls {
Richard Trieu02552272017-05-02 23:58:52 +0000872#define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \
873 typedef int INT; \
874 struct NAME { \
875 public: \
876 private: \
877 protected: \
878 static_assert(1 == 1, "Message"); \
879 static_assert(2 == 2); \
880 \
881 int x; \
882 double y; \
883 \
884 INT z; \
885 \
886 unsigned a : 1; \
887 unsigned b : 2 * 2 + 5 / 2; \
888 \
889 mutable int c = sizeof(x + y); \
890 \
891 void method() {} \
892 static void static_method() {} \
893 virtual void virtual_method() {} \
894 virtual void pure_virtual_method() = 0; \
895 inline void inline_method() {} \
896 void volatile_method() volatile {} \
897 void const_method() const {} \
898 \
899 typedef int typedef_int; \
900 using using_int = int; \
901 \
902 void method_one_arg(int x) {} \
903 void method_one_arg_default_argument(int x = 5 + 5) {} \
904 void method_decayed_type(int x[5]) {} \
905 \
906 int constant_arr[5]; \
907 \
908 ACCESS: \
Richard Trieufe564052017-04-20 02:53:53 +0000909 };
910
Richard Trieue7f7ed22017-02-22 01:11:25 +0000911#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000912CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000913#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000914CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000915#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000916S *s;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000917#endif
918
919#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000920CREATE_ALL_DECL_STRUCT(T, private)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000921#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000922CREATE_ALL_DECL_STRUCT(T, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000923#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000924T *t;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000925// expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
926// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
927#endif
928}
929
930namespace FriendFunction {
931#if defined(FIRST)
932void F(int = 0);
933struct S { friend void F(int); };
934#elif defined(SECOND)
935void F(int);
936struct S { friend void F(int); };
937#else
938S s;
939#endif
940
941#if defined(FIRST)
942void G(int = 0);
943struct T {
944 friend void G(int);
945
946 private:
947};
948#elif defined(SECOND)
949void G(int);
950struct T {
951 friend void G(int);
952
953 public:
954};
955#else
956T t;
957// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
958// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
959#endif
960} // namespace FriendFunction
961
962namespace ImplicitDecl {
963#if defined(FIRST)
964struct S { };
965void S_Constructors() {
966 // Trigger creation of implicit contructors
967 S foo;
968 S bar = foo;
969 S baz(bar);
970}
971#elif defined(SECOND)
972struct S { };
973#else
974S s;
975#endif
976
977#if defined(FIRST)
978struct T {
979 private:
980};
981void T_Constructors() {
982 // Trigger creation of implicit contructors
983 T foo;
984 T bar = foo;
985 T baz(bar);
986}
987#elif defined(SECOND)
988struct T {
989 public:
990};
991#else
992T t;
993// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
994// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
995#endif
996
997} // namespace ImplicitDelc
998
999namespace TemplatedClass {
1000#if defined(FIRST)
1001template <class>
1002struct S {};
1003#elif defined(SECOND)
1004template <class>
1005struct S {};
1006#else
1007S<int> s;
1008#endif
1009
1010#if defined(FIRST)
1011template <class>
1012struct T {
1013 private:
1014};
1015#elif defined(SECOND)
1016template <class>
1017struct T {
1018 public:
1019};
1020#else
1021T<int> t;
1022// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
1023// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
1024#endif
1025} // namespace TemplatedClass
1026
1027namespace TemplateClassWithField {
1028#if defined(FIRST)
1029template <class A>
1030struct S {
1031 A a;
1032};
1033#elif defined(SECOND)
1034template <class A>
1035struct S {
1036 A a;
1037};
1038#else
1039S<int> s;
1040#endif
1041
1042#if defined(FIRST)
1043template <class A>
1044struct T {
1045 A a;
1046
1047 private:
1048};
1049#elif defined(SECOND)
1050template <class A>
1051struct T {
1052 A a;
1053
1054 public:
1055};
1056#else
1057T<int> t;
1058// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
1059// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
1060#endif
1061} // namespace TemplateClassWithField
1062
1063namespace TemplateClassWithTemplateField {
1064#if defined(FIRST)
1065template <class A>
1066class WrapperS;
1067template <class A>
1068struct S {
1069 WrapperS<A> a;
1070};
1071#elif defined(SECOND)
1072template <class A>
1073class WrapperS;
1074template <class A>
1075struct S {
1076 WrapperS<A> a;
1077};
1078#else
1079template <class A>
1080class WrapperS{};
1081S<int> s;
1082#endif
1083
1084#if defined(FIRST)
1085template <class A>
1086class WrapperT;
1087template <class A>
1088struct T {
1089 WrapperT<A> a;
1090
1091 public:
1092};
1093#elif defined(SECOND)
1094template <class A>
1095class WrapperT;
1096template <class A>
1097struct T {
1098 WrapperT<A> a;
1099
1100 private:
1101};
1102#else
1103template <class A>
1104class WrapperT{};
1105T<int> t;
1106// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1107// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1108#endif
1109} // namespace TemplateClassWithTemplateField
1110
1111namespace EnumWithForwardDeclaration {
1112#if defined(FIRST)
1113enum E : int;
1114struct S {
1115 void get(E) {}
1116};
1117#elif defined(SECOND)
1118enum E : int { A, B };
1119struct S {
1120 void get(E) {}
1121};
1122#else
1123S s;
1124#endif
1125
1126#if defined(FIRST)
1127struct T {
1128 void get(E) {}
1129 public:
1130};
1131#elif defined(SECOND)
1132struct T {
1133 void get(E) {}
1134 private:
1135};
1136#else
1137T t;
1138// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1139// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1140#endif
1141} // namespace EnumWithForwardDeclaration
1142
1143namespace StructWithForwardDeclaration {
1144#if defined(FIRST)
1145struct P {};
1146struct S {
1147 struct P *ptr;
1148};
1149#elif defined(SECOND)
1150struct S {
1151 struct P *ptr;
1152};
1153#else
1154S s;
1155#endif
1156
1157#if defined(FIRST)
1158struct Q {};
1159struct T {
1160 struct Q *ptr;
1161 public:
1162};
1163#elif defined(SECOND)
1164struct T {
1165 struct Q *ptr;
1166 private:
1167};
1168#else
1169T t;
1170// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1171// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1172#endif
1173} // namespace StructWithForwardDeclaration
1174
1175namespace StructWithForwardDeclarationNoDefinition {
1176#if defined(FIRST)
1177struct P;
1178struct S {
1179 struct P *ptr;
1180};
1181#elif defined(SECOND)
1182struct S {
1183 struct P *ptr;
1184};
1185#else
1186S s;
1187#endif
1188
1189#if defined(FIRST)
1190struct Q;
1191struct T {
1192 struct Q *ptr;
1193
1194 public:
1195};
1196#elif defined(SECOND)
1197struct T {
1198 struct Q *ptr;
1199
1200 private:
1201};
1202#else
1203T t;
1204// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::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 StructWithForwardDeclarationNoDefinition
1208
Richard Trieufe564052017-04-20 02:53:53 +00001209namespace LateParsedDefaultArgument {
1210#if defined(FIRST)
1211template <typename T>
1212struct S {
1213 struct R {
1214 void foo(T x = 0) {}
1215 };
1216};
1217#elif defined(SECOND)
1218#else
1219void run() {
1220 S<int>::R().foo();
1221}
1222#endif
1223}
1224
1225namespace LateParsedDefaultArgument {
1226#if defined(FIRST)
1227template <typename alpha> struct Bravo {
1228 void charlie(bool delta = false) {}
1229};
1230typedef Bravo<char> echo;
1231echo foxtrot;
1232
1233Bravo<char> golf;
1234#elif defined(SECOND)
1235#else
1236#endif
1237}
1238
Richard Trieu157ed942017-04-28 22:03:28 +00001239namespace DifferentParameterNameInTemplate {
1240#if defined(FIRST) || defined(SECOND)
1241template <typename T>
1242struct S {
1243 typedef T Type;
1244
1245 static void Run(const Type *name_one);
1246};
1247
1248template <typename T>
1249void S<T>::Run(const T *name_two) {}
1250
1251template <typename T>
1252struct Foo {
1253 ~Foo() { Handler::Run(nullptr); }
1254 Foo() {}
1255
1256 class Handler : public S<T> {};
1257
1258 void Get(typename Handler::Type *x = nullptr) {}
1259 void Add() { Handler::Run(nullptr); }
1260};
1261#endif
1262
1263#if defined(FIRST)
1264struct Beta;
1265
1266struct Alpha {
1267 Alpha();
1268 void Go() { betas.Get(); }
1269 Foo<Beta> betas;
1270};
1271
1272#elif defined(SECOND)
1273struct Beta {};
1274
1275struct BetaHelper {
1276 void add_Beta() { betas.Add(); }
1277 Foo<Beta> betas;
1278};
1279
1280#else
1281Alpha::Alpha() {}
1282#endif
1283}
1284
Richard Trieu02552272017-05-02 23:58:52 +00001285namespace ParameterTest {
1286#if defined(FIRST)
1287class X {};
1288template <typename G>
1289class S {
1290 public:
1291 typedef G Type;
1292 static inline G *Foo(const G *a, int * = nullptr);
1293};
1294
1295template<typename G>
1296G* S<G>::Foo(const G* aaaa, int*) {}
1297#elif defined(SECOND)
1298template <typename G>
1299class S {
1300 public:
1301 typedef G Type;
1302 static inline G *Foo(const G *a, int * = nullptr);
1303};
1304
1305template<typename G>
1306G* S<G>::Foo(const G* asdf, int*) {}
1307#else
1308S<X> s;
1309#endif
1310}
1311
Richard Trieub35ef2a2017-05-09 03:24:34 +00001312namespace MultipleTypedefs {
1313#if defined(FIRST)
1314typedef int B1;
1315typedef B1 A1;
1316struct S1 {
1317 A1 x;
1318};
1319#elif defined(SECOND)
1320typedef int A1;
1321struct S1 {
1322 A1 x;
1323};
1324#else
1325S1 s1;
1326#endif
1327
1328#if defined(FIRST)
1329struct T2 { int x; };
1330typedef T2 B2;
1331typedef B2 A2;
1332struct S2 {
1333 T2 x;
1334};
1335#elif defined(SECOND)
1336struct T2 { int x; };
1337typedef T2 A2;
1338struct S2 {
1339 T2 x;
1340};
1341#else
1342S2 s2;
1343#endif
1344}
Richard Trieu02552272017-05-02 23:58:52 +00001345
Richard Trieue7f7ed22017-02-22 01:11:25 +00001346// Keep macros contained to one file.
1347#ifdef FIRST
1348#undef FIRST
1349#endif
1350#ifdef SECOND
1351#undef SECOND
1352#endif