blob: 58814dd6b3fb819cbb875580775b8ffb2fa44fca [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
Hans Wennborg22707762017-04-12 16:40:26 +0000637
Richard Trieue7f7ed22017-02-22 01:11:25 +0000638// Interesting cases that should not cause errors. struct S should not error
639// while struct T should error at the access specifier mismatch at the end.
640namespace AllDecls {
Richard Trieu02552272017-05-02 23:58:52 +0000641#define CREATE_ALL_DECL_STRUCT(NAME, ACCESS) \
642 typedef int INT; \
643 struct NAME { \
644 public: \
645 private: \
646 protected: \
647 static_assert(1 == 1, "Message"); \
648 static_assert(2 == 2); \
649 \
650 int x; \
651 double y; \
652 \
653 INT z; \
654 \
655 unsigned a : 1; \
656 unsigned b : 2 * 2 + 5 / 2; \
657 \
658 mutable int c = sizeof(x + y); \
659 \
660 void method() {} \
661 static void static_method() {} \
662 virtual void virtual_method() {} \
663 virtual void pure_virtual_method() = 0; \
664 inline void inline_method() {} \
665 void volatile_method() volatile {} \
666 void const_method() const {} \
667 \
668 typedef int typedef_int; \
669 using using_int = int; \
670 \
671 void method_one_arg(int x) {} \
672 void method_one_arg_default_argument(int x = 5 + 5) {} \
673 void method_decayed_type(int x[5]) {} \
674 \
675 int constant_arr[5]; \
676 \
677 ACCESS: \
Richard Trieufe564052017-04-20 02:53:53 +0000678 };
679
Richard Trieue7f7ed22017-02-22 01:11:25 +0000680#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000681CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000682#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000683CREATE_ALL_DECL_STRUCT(S, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000684#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000685S *s;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000686#endif
687
688#if defined(FIRST)
Richard Trieufe564052017-04-20 02:53:53 +0000689CREATE_ALL_DECL_STRUCT(T, private)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000690#elif defined(SECOND)
Richard Trieufe564052017-04-20 02:53:53 +0000691CREATE_ALL_DECL_STRUCT(T, public)
Richard Trieue7f7ed22017-02-22 01:11:25 +0000692#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000693T *t;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000694// expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
695// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
696#endif
697}
698
699namespace FriendFunction {
700#if defined(FIRST)
701void F(int = 0);
702struct S { friend void F(int); };
703#elif defined(SECOND)
704void F(int);
705struct S { friend void F(int); };
706#else
707S s;
708#endif
709
710#if defined(FIRST)
711void G(int = 0);
712struct T {
713 friend void G(int);
714
715 private:
716};
717#elif defined(SECOND)
718void G(int);
719struct T {
720 friend void G(int);
721
722 public:
723};
724#else
725T t;
726// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
727// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
728#endif
729} // namespace FriendFunction
730
731namespace ImplicitDecl {
732#if defined(FIRST)
733struct S { };
734void S_Constructors() {
735 // Trigger creation of implicit contructors
736 S foo;
737 S bar = foo;
738 S baz(bar);
739}
740#elif defined(SECOND)
741struct S { };
742#else
743S s;
744#endif
745
746#if defined(FIRST)
747struct T {
748 private:
749};
750void T_Constructors() {
751 // Trigger creation of implicit contructors
752 T foo;
753 T bar = foo;
754 T baz(bar);
755}
756#elif defined(SECOND)
757struct T {
758 public:
759};
760#else
761T t;
762// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
763// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
764#endif
765
766} // namespace ImplicitDelc
767
768namespace TemplatedClass {
769#if defined(FIRST)
770template <class>
771struct S {};
772#elif defined(SECOND)
773template <class>
774struct S {};
775#else
776S<int> s;
777#endif
778
779#if defined(FIRST)
780template <class>
781struct T {
782 private:
783};
784#elif defined(SECOND)
785template <class>
786struct T {
787 public:
788};
789#else
790T<int> t;
791// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
792// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
793#endif
794} // namespace TemplatedClass
795
796namespace TemplateClassWithField {
797#if defined(FIRST)
798template <class A>
799struct S {
800 A a;
801};
802#elif defined(SECOND)
803template <class A>
804struct S {
805 A a;
806};
807#else
808S<int> s;
809#endif
810
811#if defined(FIRST)
812template <class A>
813struct T {
814 A a;
815
816 private:
817};
818#elif defined(SECOND)
819template <class A>
820struct T {
821 A a;
822
823 public:
824};
825#else
826T<int> t;
827// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
828// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
829#endif
830} // namespace TemplateClassWithField
831
832namespace TemplateClassWithTemplateField {
833#if defined(FIRST)
834template <class A>
835class WrapperS;
836template <class A>
837struct S {
838 WrapperS<A> a;
839};
840#elif defined(SECOND)
841template <class A>
842class WrapperS;
843template <class A>
844struct S {
845 WrapperS<A> a;
846};
847#else
848template <class A>
849class WrapperS{};
850S<int> s;
851#endif
852
853#if defined(FIRST)
854template <class A>
855class WrapperT;
856template <class A>
857struct T {
858 WrapperT<A> a;
859
860 public:
861};
862#elif defined(SECOND)
863template <class A>
864class WrapperT;
865template <class A>
866struct T {
867 WrapperT<A> a;
868
869 private:
870};
871#else
872template <class A>
873class WrapperT{};
874T<int> t;
875// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
876// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
877#endif
878} // namespace TemplateClassWithTemplateField
879
880namespace EnumWithForwardDeclaration {
881#if defined(FIRST)
882enum E : int;
883struct S {
884 void get(E) {}
885};
886#elif defined(SECOND)
887enum E : int { A, B };
888struct S {
889 void get(E) {}
890};
891#else
892S s;
893#endif
894
895#if defined(FIRST)
896struct T {
897 void get(E) {}
898 public:
899};
900#elif defined(SECOND)
901struct T {
902 void get(E) {}
903 private:
904};
905#else
906T t;
907// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
908// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
909#endif
910} // namespace EnumWithForwardDeclaration
911
912namespace StructWithForwardDeclaration {
913#if defined(FIRST)
914struct P {};
915struct S {
916 struct P *ptr;
917};
918#elif defined(SECOND)
919struct S {
920 struct P *ptr;
921};
922#else
923S s;
924#endif
925
926#if defined(FIRST)
927struct Q {};
928struct T {
929 struct Q *ptr;
930 public:
931};
932#elif defined(SECOND)
933struct T {
934 struct Q *ptr;
935 private:
936};
937#else
938T t;
939// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
940// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
941#endif
942} // namespace StructWithForwardDeclaration
943
944namespace StructWithForwardDeclarationNoDefinition {
945#if defined(FIRST)
946struct P;
947struct S {
948 struct P *ptr;
949};
950#elif defined(SECOND)
951struct S {
952 struct P *ptr;
953};
954#else
955S s;
956#endif
957
958#if defined(FIRST)
959struct Q;
960struct T {
961 struct Q *ptr;
962
963 public:
964};
965#elif defined(SECOND)
966struct T {
967 struct Q *ptr;
968
969 private:
970};
971#else
972T t;
973// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
974// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
975#endif
976} // namespace StructWithForwardDeclarationNoDefinition
977
Richard Trieufe564052017-04-20 02:53:53 +0000978namespace LateParsedDefaultArgument {
979#if defined(FIRST)
980template <typename T>
981struct S {
982 struct R {
983 void foo(T x = 0) {}
984 };
985};
986#elif defined(SECOND)
987#else
988void run() {
989 S<int>::R().foo();
990}
991#endif
992}
993
994namespace LateParsedDefaultArgument {
995#if defined(FIRST)
996template <typename alpha> struct Bravo {
997 void charlie(bool delta = false) {}
998};
999typedef Bravo<char> echo;
1000echo foxtrot;
1001
1002Bravo<char> golf;
1003#elif defined(SECOND)
1004#else
1005#endif
1006}
1007
Richard Trieu157ed942017-04-28 22:03:28 +00001008namespace DifferentParameterNameInTemplate {
1009#if defined(FIRST) || defined(SECOND)
1010template <typename T>
1011struct S {
1012 typedef T Type;
1013
1014 static void Run(const Type *name_one);
1015};
1016
1017template <typename T>
1018void S<T>::Run(const T *name_two) {}
1019
1020template <typename T>
1021struct Foo {
1022 ~Foo() { Handler::Run(nullptr); }
1023 Foo() {}
1024
1025 class Handler : public S<T> {};
1026
1027 void Get(typename Handler::Type *x = nullptr) {}
1028 void Add() { Handler::Run(nullptr); }
1029};
1030#endif
1031
1032#if defined(FIRST)
1033struct Beta;
1034
1035struct Alpha {
1036 Alpha();
1037 void Go() { betas.Get(); }
1038 Foo<Beta> betas;
1039};
1040
1041#elif defined(SECOND)
1042struct Beta {};
1043
1044struct BetaHelper {
1045 void add_Beta() { betas.Add(); }
1046 Foo<Beta> betas;
1047};
1048
1049#else
1050Alpha::Alpha() {}
1051#endif
1052}
1053
Richard Trieu02552272017-05-02 23:58:52 +00001054namespace ParameterTest {
1055#if defined(FIRST)
1056class X {};
1057template <typename G>
1058class S {
1059 public:
1060 typedef G Type;
1061 static inline G *Foo(const G *a, int * = nullptr);
1062};
1063
1064template<typename G>
1065G* S<G>::Foo(const G* aaaa, int*) {}
1066#elif defined(SECOND)
1067template <typename G>
1068class S {
1069 public:
1070 typedef G Type;
1071 static inline G *Foo(const G *a, int * = nullptr);
1072};
1073
1074template<typename G>
1075G* S<G>::Foo(const G* asdf, int*) {}
1076#else
1077S<X> s;
1078#endif
1079}
1080
Richard Trieub35ef2a2017-05-09 03:24:34 +00001081namespace MultipleTypedefs {
1082#if defined(FIRST)
1083typedef int B1;
1084typedef B1 A1;
1085struct S1 {
1086 A1 x;
1087};
1088#elif defined(SECOND)
1089typedef int A1;
1090struct S1 {
1091 A1 x;
1092};
1093#else
1094S1 s1;
1095#endif
1096
1097#if defined(FIRST)
1098struct T2 { int x; };
1099typedef T2 B2;
1100typedef B2 A2;
1101struct S2 {
1102 T2 x;
1103};
1104#elif defined(SECOND)
1105struct T2 { int x; };
1106typedef T2 A2;
1107struct S2 {
1108 T2 x;
1109};
1110#else
1111S2 s2;
1112#endif
1113}
Richard Trieu02552272017-05-02 23:58:52 +00001114
Richard Trieue7f7ed22017-02-22 01:11:25 +00001115// Keep macros contained to one file.
1116#ifdef FIRST
1117#undef FIRST
1118#endif
1119#ifdef SECOND
1120#undef SECOND
1121#endif