blob: 63bf1e6f5f3c2a04ae7df0558a16652d275f5921 [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 Trieue7f7ed22017-02-22 01:11:25 +0000710// Interesting cases that should not cause errors. struct S should not error
711// while struct T should error at the access specifier mismatch at the end.
712namespace AllDecls {
Richard Trieu02552272017-05-02 23:58:52 +0000713#define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \
714 typedef int INT; \
715 struct NAME { \
716 public: \
717 private: \
718 protected: \
719 static_assert(1 == 1, "Message"); \
720 static_assert(2 == 2); \
721 \
722 int x; \
723 double y; \
724 \
725 INT z; \
726 \
727 unsigned a : 1; \
728 unsigned b : 2 * 2 + 5 / 2; \
729 \
730 mutable int c = sizeof(x + y); \
731 \
732 void method() {} \
733 static void static_method() {} \
734 virtual void virtual_method() {} \
735 virtual void pure_virtual_method() = 0; \
736 inline void inline_method() {} \
737 void volatile_method() volatile {} \
738 void const_method() const {} \
739 \
740 typedef int typedef_int; \
741 using using_int = int; \
742 \
743 void method_one_arg(int x) {} \
744 void method_one_arg_default_argument(int x = 5 + 5) {} \
745 void method_decayed_type(int x[5]) {} \
746 \
747 int constant_arr[5]; \
748 \
749 ACCESS: \
Richard Trieufe564052017-04-20 02:53:53 +0000750 };
751
Richard Trieue7f7ed22017-02-22 01:11:25 +0000752#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000753CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000754#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000755CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000756#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000757S *s;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000758#endif
759
760#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000761CREATE_ALL_DECL_STRUCT(T, private)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000762#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000763CREATE_ALL_DECL_STRUCT(T, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000764#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000765T *t;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000766// expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
767// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
768#endif
769}
770
771namespace FriendFunction {
772#if defined(FIRST)
773void F(int = 0);
774struct S { friend void F(int); };
775#elif defined(SECOND)
776void F(int);
777struct S { friend void F(int); };
778#else
779S s;
780#endif
781
782#if defined(FIRST)
783void G(int = 0);
784struct T {
785 friend void G(int);
786
787 private:
788};
789#elif defined(SECOND)
790void G(int);
791struct T {
792 friend void G(int);
793
794 public:
795};
796#else
797T t;
798// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
799// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
800#endif
801} // namespace FriendFunction
802
803namespace ImplicitDecl {
804#if defined(FIRST)
805struct S { };
806void S_Constructors() {
807 // Trigger creation of implicit contructors
808 S foo;
809 S bar = foo;
810 S baz(bar);
811}
812#elif defined(SECOND)
813struct S { };
814#else
815S s;
816#endif
817
818#if defined(FIRST)
819struct T {
820 private:
821};
822void T_Constructors() {
823 // Trigger creation of implicit contructors
824 T foo;
825 T bar = foo;
826 T baz(bar);
827}
828#elif defined(SECOND)
829struct T {
830 public:
831};
832#else
833T t;
834// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
835// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
836#endif
837
838} // namespace ImplicitDelc
839
840namespace TemplatedClass {
841#if defined(FIRST)
842template <class>
843struct S {};
844#elif defined(SECOND)
845template <class>
846struct S {};
847#else
848S<int> s;
849#endif
850
851#if defined(FIRST)
852template <class>
853struct T {
854 private:
855};
856#elif defined(SECOND)
857template <class>
858struct T {
859 public:
860};
861#else
862T<int> t;
863// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
864// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
865#endif
866} // namespace TemplatedClass
867
868namespace TemplateClassWithField {
869#if defined(FIRST)
870template <class A>
871struct S {
872 A a;
873};
874#elif defined(SECOND)
875template <class A>
876struct S {
877 A a;
878};
879#else
880S<int> s;
881#endif
882
883#if defined(FIRST)
884template <class A>
885struct T {
886 A a;
887
888 private:
889};
890#elif defined(SECOND)
891template <class A>
892struct T {
893 A a;
894
895 public:
896};
897#else
898T<int> t;
899// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
900// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
901#endif
902} // namespace TemplateClassWithField
903
904namespace TemplateClassWithTemplateField {
905#if defined(FIRST)
906template <class A>
907class WrapperS;
908template <class A>
909struct S {
910 WrapperS<A> a;
911};
912#elif defined(SECOND)
913template <class A>
914class WrapperS;
915template <class A>
916struct S {
917 WrapperS<A> a;
918};
919#else
920template <class A>
921class WrapperS{};
922S<int> s;
923#endif
924
925#if defined(FIRST)
926template <class A>
927class WrapperT;
928template <class A>
929struct T {
930 WrapperT<A> a;
931
932 public:
933};
934#elif defined(SECOND)
935template <class A>
936class WrapperT;
937template <class A>
938struct T {
939 WrapperT<A> a;
940
941 private:
942};
943#else
944template <class A>
945class WrapperT{};
946T<int> t;
947// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
948// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
949#endif
950} // namespace TemplateClassWithTemplateField
951
952namespace EnumWithForwardDeclaration {
953#if defined(FIRST)
954enum E : int;
955struct S {
956 void get(E) {}
957};
958#elif defined(SECOND)
959enum E : int { A, B };
960struct S {
961 void get(E) {}
962};
963#else
964S s;
965#endif
966
967#if defined(FIRST)
968struct T {
969 void get(E) {}
970 public:
971};
972#elif defined(SECOND)
973struct T {
974 void get(E) {}
975 private:
976};
977#else
978T t;
979// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
980// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
981#endif
982} // namespace EnumWithForwardDeclaration
983
984namespace StructWithForwardDeclaration {
985#if defined(FIRST)
986struct P {};
987struct S {
988 struct P *ptr;
989};
990#elif defined(SECOND)
991struct S {
992 struct P *ptr;
993};
994#else
995S s;
996#endif
997
998#if defined(FIRST)
999struct Q {};
1000struct T {
1001 struct Q *ptr;
1002 public:
1003};
1004#elif defined(SECOND)
1005struct T {
1006 struct Q *ptr;
1007 private:
1008};
1009#else
1010T t;
1011// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1012// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1013#endif
1014} // namespace StructWithForwardDeclaration
1015
1016namespace StructWithForwardDeclarationNoDefinition {
1017#if defined(FIRST)
1018struct P;
1019struct S {
1020 struct P *ptr;
1021};
1022#elif defined(SECOND)
1023struct S {
1024 struct P *ptr;
1025};
1026#else
1027S s;
1028#endif
1029
1030#if defined(FIRST)
1031struct Q;
1032struct T {
1033 struct Q *ptr;
1034
1035 public:
1036};
1037#elif defined(SECOND)
1038struct T {
1039 struct Q *ptr;
1040
1041 private:
1042};
1043#else
1044T t;
1045// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1046// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1047#endif
1048} // namespace StructWithForwardDeclarationNoDefinition
1049
Richard Trieufe564052017-04-20 02:53:53 +00001050namespace LateParsedDefaultArgument {
1051#if defined(FIRST)
1052template <typename T>
1053struct S {
1054 struct R {
1055 void foo(T x = 0) {}
1056 };
1057};
1058#elif defined(SECOND)
1059#else
1060void run() {
1061 S<int>::R().foo();
1062}
1063#endif
1064}
1065
1066namespace LateParsedDefaultArgument {
1067#if defined(FIRST)
1068template <typename alpha> struct Bravo {
1069 void charlie(bool delta = false) {}
1070};
1071typedef Bravo<char> echo;
1072echo foxtrot;
1073
1074Bravo<char> golf;
1075#elif defined(SECOND)
1076#else
1077#endif
1078}
1079
Richard Trieu157ed942017-04-28 22:03:28 +00001080namespace DifferentParameterNameInTemplate {
1081#if defined(FIRST) || defined(SECOND)
1082template <typename T>
1083struct S {
1084 typedef T Type;
1085
1086 static void Run(const Type *name_one);
1087};
1088
1089template <typename T>
1090void S<T>::Run(const T *name_two) {}
1091
1092template <typename T>
1093struct Foo {
1094 ~Foo() { Handler::Run(nullptr); }
1095 Foo() {}
1096
1097 class Handler : public S<T> {};
1098
1099 void Get(typename Handler::Type *x = nullptr) {}
1100 void Add() { Handler::Run(nullptr); }
1101};
1102#endif
1103
1104#if defined(FIRST)
1105struct Beta;
1106
1107struct Alpha {
1108 Alpha();
1109 void Go() { betas.Get(); }
1110 Foo<Beta> betas;
1111};
1112
1113#elif defined(SECOND)
1114struct Beta {};
1115
1116struct BetaHelper {
1117 void add_Beta() { betas.Add(); }
1118 Foo<Beta> betas;
1119};
1120
1121#else
1122Alpha::Alpha() {}
1123#endif
1124}
1125
Richard Trieu02552272017-05-02 23:58:52 +00001126namespace ParameterTest {
1127#if defined(FIRST)
1128class X {};
1129template <typename G>
1130class S {
1131 public:
1132 typedef G Type;
1133 static inline G *Foo(const G *a, int * = nullptr);
1134};
1135
1136template<typename G>
1137G* S<G>::Foo(const G* aaaa, int*) {}
1138#elif defined(SECOND)
1139template <typename G>
1140class S {
1141 public:
1142 typedef G Type;
1143 static inline G *Foo(const G *a, int * = nullptr);
1144};
1145
1146template<typename G>
1147G* S<G>::Foo(const G* asdf, int*) {}
1148#else
1149S<X> s;
1150#endif
1151}
1152
Richard Trieub35ef2a2017-05-09 03:24:34 +00001153namespace MultipleTypedefs {
1154#if defined(FIRST)
1155typedef int B1;
1156typedef B1 A1;
1157struct S1 {
1158 A1 x;
1159};
1160#elif defined(SECOND)
1161typedef int A1;
1162struct S1 {
1163 A1 x;
1164};
1165#else
1166S1 s1;
1167#endif
1168
1169#if defined(FIRST)
1170struct T2 { int x; };
1171typedef T2 B2;
1172typedef B2 A2;
1173struct S2 {
1174 T2 x;
1175};
1176#elif defined(SECOND)
1177struct T2 { int x; };
1178typedef T2 A2;
1179struct S2 {
1180 T2 x;
1181};
1182#else
1183S2 s2;
1184#endif
1185}
Richard Trieu02552272017-05-02 23:58:52 +00001186
Richard Trieue7f7ed22017-02-22 01:11:25 +00001187// Keep macros contained to one file.
1188#ifdef FIRST
1189#undef FIRST
1190#endif
1191#ifdef SECOND
1192#undef SECOND
1193#endif