blob: b22ccdd0c8b6e54c1a8b862c34e5c3caa347f535 [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
Richard Trieu73cf9242017-11-04 01:20:50 +000015// Test that each header can compile
16// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++1z %t/Inputs/first.h
17// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++1z %t/Inputs/second.h
18
Richard Trieue7f7ed22017-02-22 01:11:25 +000019// Build module map file
20// RUN: echo "module FirstModule {" >> %t/Inputs/module.map
21// RUN: echo " header \"first.h\"" >> %t/Inputs/module.map
22// RUN: echo "}" >> %t/Inputs/module.map
23// RUN: echo "module SecondModule {" >> %t/Inputs/module.map
24// RUN: echo " header \"second.h\"" >> %t/Inputs/module.map
25// RUN: echo "}" >> %t/Inputs/module.map
26
27// Run test
Richard Trieu639d7b62017-02-22 22:22:42 +000028// 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 +000029
30#if !defined(FIRST) && !defined(SECOND)
31#include "first.h"
32#include "second.h"
33#endif
34
Richard Trieu73cf9242017-11-04 01:20:50 +000035// Used for testing
36#if defined(FIRST)
37#define ACCESS public:
38#elif defined(SECOND)
39#define ACCESS private:
40#endif
41
Richard Trieue7f7ed22017-02-22 01:11:25 +000042namespace AccessSpecifiers {
43#if defined(FIRST)
44struct S1 {
45};
46#elif defined(SECOND)
47struct S1 {
48 private:
49};
50#else
51S1 s1;
52// expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
53// expected-note@first.h:* {{but in 'FirstModule' found end of class}}
54#endif
55
56#if defined(FIRST)
57struct S2 {
58 public:
59};
60#elif defined(SECOND)
61struct S2 {
62 protected:
63};
64#else
65S2 s2;
66// expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}}
67// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
68#endif
Richard Trieu73cf9242017-11-04 01:20:50 +000069
70#define DECLS \
71public: \
72private: \
73protected:
74
75#if defined(FIRST) || defined(SECOND)
76struct Valid1 {
77 DECLS
78};
79#else
80Valid1 v1;
81#endif
82
83#if defined(FIRST) || defined(SECOND)
84struct Invalid1 {
85 DECLS
86 ACCESS
87};
88#else
89Invalid1 i1;
90// expected-error@second.h:* {{'AccessSpecifiers::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
91// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
92#endif
93
94#undef DECLS
Richard Trieue7f7ed22017-02-22 01:11:25 +000095} // namespace AccessSpecifiers
96
Richard Trieu639d7b62017-02-22 22:22:42 +000097namespace StaticAssert {
98#if defined(FIRST)
99struct S1 {
100 static_assert(1 == 1, "First");
101};
102#elif defined(SECOND)
103struct S1 {
104 static_assert(1 == 1, "Second");
105};
106#else
107S1 s1;
108// expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}}
109// expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}}
110#endif
111
112#if defined(FIRST)
113struct S2 {
114 static_assert(2 == 2, "Message");
115};
116#elif defined(SECOND)
117struct S2 {
118 static_assert(2 == 2);
119};
120#else
121S2 s2;
122// 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}}
123// expected-note@first.h:* {{but in 'FirstModule' found static assert with message}}
124#endif
125
126#if defined(FIRST)
127struct S3 {
128 static_assert(3 == 3, "Message");
129};
130#elif defined(SECOND)
131struct S3 {
132 static_assert(3 != 4, "Message");
133};
134#else
135S3 s3;
136// expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}}
137// expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}}
138#endif
139
140#if defined(FIRST)
141struct S4 {
142 static_assert(4 == 4, "Message");
143};
144#elif defined(SECOND)
145struct S4 {
146 public:
147};
148#else
149S4 s4;
150// expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
151// expected-note@first.h:* {{but in 'FirstModule' found static assert}}
152#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000153
154#define DECLS \
155 static_assert(4 == 4, "Message"); \
156 static_assert(5 == 5);
157
158#if defined(FIRST) || defined(SECOND)
159struct Valid1 {
160 DECLS
161};
162#else
163Valid1 v1;
164#endif
165
166#if defined(FIRST) || defined(SECOND)
167struct Invalid1 {
168 DECLS
169 ACCESS
170};
171#else
172Invalid1 i1;
173// expected-error@second.h:* {{'StaticAssert::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
174// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
175#endif
176#undef DECLS
177} // namespace StaticAssert
Richard Trieu639d7b62017-02-22 22:22:42 +0000178
Richard Trieud0786092017-02-23 00:23:01 +0000179namespace Field {
180#if defined(FIRST)
181struct S1 {
182 int x;
183 private:
184 int y;
185};
186#elif defined(SECOND)
187struct S1 {
188 int x;
189 int y;
190};
191#else
192S1 s1;
193// expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
194// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
195#endif
196
197#if defined(FIRST)
198struct S2 {
199 int x;
200 int y;
201};
202#elif defined(SECOND)
203struct S2 {
204 int y;
205 int x;
206};
207#else
208S2 s2;
209// expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
210// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
211#endif
Richard Trieubcaaf962017-02-23 03:25:57 +0000212
213#if defined(FIRST)
214struct S3 {
215 double x;
216};
217#elif defined(SECOND)
218struct S3 {
219 int x;
220};
221#else
222S3 s3;
223// expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}}
224// expected-note@second.h:* {{declaration of 'x' does not match}}
225#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000226
227#if defined(FIRST)
228typedef int A;
229struct S4 {
230 A x;
231};
232
233struct S5 {
234 A x;
235};
236#elif defined(SECOND)
237typedef int B;
238struct S4 {
239 B x;
240};
241
242struct S5 {
243 int x;
244};
245#else
246S4 s4;
Alex Lorenz76377dc2017-03-10 15:04:58 +0000247// 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')}}
248// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000249
250S5 s5;
251// 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 +0000252// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000253#endif
254
Richard Trieu93772fc2017-02-24 20:59:28 +0000255#if defined(FIRST)
256struct S6 {
257 unsigned x;
258};
259#elif defined(SECOND)
260struct S6 {
261 unsigned x : 1;
262};
263#else
264S6 s6;
265// expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}}
266// expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}}
267#endif
268
269#if defined(FIRST)
270struct S7 {
271 unsigned x : 2;
272};
273#elif defined(SECOND)
274struct S7 {
275 unsigned x : 1;
276};
277#else
278S7 s7;
279// 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}}
280// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
281#endif
282
283#if defined(FIRST)
284struct S8 {
285 unsigned x : 2;
286};
287#elif defined(SECOND)
288struct S8 {
289 unsigned x : 1 + 1;
290};
291#else
292S8 s8;
293// 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}}
294// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
295#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000296
Richard Trieu8d543e22017-02-24 23:35:37 +0000297#if defined(FIRST)
298struct S9 {
299 mutable int x;
300};
301#elif defined(SECOND)
302struct S9 {
303 int x;
304};
305#else
306S9 s9;
307// expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
308// expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}}
309#endif
310
311#if defined(FIRST)
312struct S10 {
313 unsigned x = 5;
314};
315#elif defined(SECOND)
316struct S10 {
317 unsigned x;
318};
319#else
320S10 s10;
321// 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}}
322// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}}
323#endif
324
325#if defined(FIRST)
326struct S11 {
327 unsigned x = 5;
328};
329#elif defined(SECOND)
330struct S11 {
331 unsigned x = 7;
332};
333#else
334S11 s11;
335// 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}}
336// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
337#endif
338
Richard Trieu02552272017-05-02 23:58:52 +0000339#if defined(FIRST)
340struct S12 {
341 unsigned x[5];
342};
343#elif defined(SECOND)
344struct S12 {
345 unsigned x[7];
346};
347#else
348S12 s12;
349// expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}}
350// expected-note@second.h:* {{declaration of 'x' does not match}}
351#endif
352
353#if defined(FIRST)
354struct S13 {
355 unsigned x[7];
356};
357#elif defined(SECOND)
358struct S13 {
359 double x[7];
360};
361#else
362S13 s13;
363// expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}}
364// expected-note@second.h:* {{declaration of 'x' does not match}}
365#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000366
367#define DECLS \
368 int a; \
369 int b : 3; \
370 unsigned c : 1 + 2; \
371 s d; \
372 double e = 1.0; \
373 long f[5];
374
375#if defined(FIRST) || defined(SECOND)
376typedef short s;
377#endif
378
379#if defined(FIRST) || defined(SECOND)
380struct Valid1 {
381 DECLS
382};
383#else
384Valid1 v1;
385#endif
386
387#if defined(FIRST) || defined(SECOND)
388struct Invalid1 {
389 DECLS
390 ACCESS
391};
392#else
393Invalid1 i1;
394// expected-error@second.h:* {{'Field::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
395// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
396#endif
397#undef DECLS
Richard Trieud0786092017-02-23 00:23:01 +0000398} // namespace Field
399
Richard Trieu48143742017-02-28 21:24:38 +0000400namespace Method {
401#if defined(FIRST)
402struct S1 {
403 void A() {}
404};
405#elif defined(SECOND)
406struct S1 {
407 private:
408 void A() {}
409};
410#else
411S1 s1;
412// expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
413// expected-note@first.h:* {{but in 'FirstModule' found method}}
414#endif
415
416#if defined(FIRST)
417struct S2 {
418 void A() {}
419 void B() {}
420};
421#elif defined(SECOND)
422struct S2 {
423 void B() {}
424 void A() {}
425};
426#else
427S2 s2;
428// expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
429// expected-note@first.h:* {{but in 'FirstModule' found method 'A'}}
430#endif
Richard Trieu583e2c12017-03-04 00:08:58 +0000431
432#if defined(FIRST)
433struct S3 {
434 static void A() {}
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000435 void A(int) {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000436};
437#elif defined(SECOND)
438struct S3 {
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000439 void A(int) {}
440 static void A() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000441};
442#else
443S3 s3;
444// 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}}
445// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}}
446#endif
447
448#if defined(FIRST)
449struct S4 {
450 virtual void A() {}
451 void B() {}
452};
453#elif defined(SECOND)
454struct S4 {
455 void A() {}
456 virtual void B() {}
457};
458#else
459S4 s4;
460// 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}}
461// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}}
462#endif
463
464#if defined(FIRST)
465struct S5 {
466 virtual void A() = 0;
467 virtual void B() {};
468};
469#elif defined(SECOND)
470struct S5 {
471 virtual void A() {}
472 virtual void B() = 0;
473};
474#else
475S5 *s5;
476// expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
477// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}}
478#endif
479
480#if defined(FIRST)
481struct S6 {
482 inline void A() {}
483};
484#elif defined(SECOND)
485struct S6 {
486 void A() {}
487};
488#else
489S6 s6;
490// 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}}
491// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}}
492#endif
493
494#if defined(FIRST)
495struct S7 {
496 void A() volatile {}
497 void A() {}
498};
499#elif defined(SECOND)
500struct S7 {
501 void A() {}
502 void A() volatile {}
503};
504#else
505S7 s7;
506// 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}}
507// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}}
508#endif
509
510#if defined(FIRST)
511struct S8 {
512 void A() const {}
513 void A() {}
514};
515#elif defined(SECOND)
516struct S8 {
517 void A() {}
518 void A() const {}
519};
520#else
521S8 s8;
522// 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}}
523// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}}
524#endif
525
Richard Trieu02552272017-05-02 23:58:52 +0000526#if defined(FIRST)
527struct S9 {
528 void A(int x) {}
529 void A(int x, int y) {}
530};
531#elif defined(SECOND)
532struct S9 {
533 void A(int x, int y) {}
534 void A(int x) {}
535};
536#else
537S9 s9;
538// 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}}
539// expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}}
540#endif
541
542#if defined(FIRST)
543struct S10 {
544 void A(int x) {}
545 void A(float x) {}
546};
547#elif defined(SECOND)
548struct S10 {
549 void A(float x) {}
550 void A(int x) {}
551};
552#else
553S10 s10;
554// 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'}}
555// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}}
556#endif
557
558#if defined(FIRST)
559struct S11 {
Richard Trieue6caa262017-12-23 00:41:01 +0000560 void A(int x);
Richard Trieu02552272017-05-02 23:58:52 +0000561};
562#elif defined(SECOND)
563struct S11 {
Richard Trieue6caa262017-12-23 00:41:01 +0000564 void A(int y);
Richard Trieu02552272017-05-02 23:58:52 +0000565};
566#else
567S11 s11;
568// 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'}}
569// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}}
570#endif
571
572#if defined(FIRST)
573struct S12 {
Richard Trieue6caa262017-12-23 00:41:01 +0000574 void A(int x);
Richard Trieu02552272017-05-02 23:58:52 +0000575};
576#elif defined(SECOND)
577struct S12 {
Richard Trieue6caa262017-12-23 00:41:01 +0000578 void A(int x = 1);
Richard Trieu02552272017-05-02 23:58:52 +0000579};
580#else
581S12 s12;
Richard Trieu6e13ff32017-06-16 02:44:29 +0000582// expected-error@second.h:* {{'Method::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter without a default argument}}
583// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}}
Richard Trieu02552272017-05-02 23:58:52 +0000584#endif
585
586#if defined(FIRST)
587struct S13 {
Richard Trieue6caa262017-12-23 00:41:01 +0000588 void A(int x = 1 + 0);
Richard Trieu02552272017-05-02 23:58:52 +0000589};
590#elif defined(SECOND)
591struct S13 {
Richard Trieue6caa262017-12-23 00:41:01 +0000592 void A(int x = 1);
Richard Trieu02552272017-05-02 23:58:52 +0000593};
594#else
595S13 s13;
Richard Trieu6e13ff32017-06-16 02:44:29 +0000596// expected-error@second.h:* {{'Method::S13' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter with a default argument}}
597// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a different default argument}}
Richard Trieu02552272017-05-02 23:58:52 +0000598#endif
599
600#if defined(FIRST)
601struct S14 {
Richard Trieue6caa262017-12-23 00:41:01 +0000602 void A(int x[2]);
Richard Trieu02552272017-05-02 23:58:52 +0000603};
604#elif defined(SECOND)
605struct S14 {
Richard Trieue6caa262017-12-23 00:41:01 +0000606 void A(int x[3]);
Richard Trieu02552272017-05-02 23:58:52 +0000607};
608#else
609S14 s14;
610// 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]'}}
611// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}}
612#endif
Richard Trieu9747a7c2017-07-14 01:36:41 +0000613
614#if defined(FIRST)
615struct S15 {
616 int A() { return 0; }
617};
618#elif defined(SECOND)
619struct S15 {
620 long A() { return 0; }
621};
622#else
623S15 s15;
624// expected-error@first.h:* {{'Method::S15::A' from module 'FirstModule' is not present in definition of 'Method::S15' in module 'SecondModule'}}
625// expected-note@second.h:* {{declaration of 'A' does not match}}
626#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000627
628#define DECLS \
629 void A(); \
630 static void B(); \
631 virtual void C(); \
632 virtual void D() = 0; \
633 inline void E(); \
634 void F() const; \
635 void G() volatile; \
636 void H(int x); \
637 void I(int x = 5 + 5); \
638 void J(int); \
639 void K(int x[2]); \
640 int L();
641
642#if defined(FIRST) || defined(SECOND)
643struct Valid1 {
644 DECLS
645};
646#else
647Valid1* v1;
648#endif
649
650#if defined(FIRST) || defined(SECOND)
651struct Invalid1 {
652 DECLS
653 ACCESS
654};
655#else
656Invalid1* i1;
657// expected-error@second.h:* {{'Method::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
658// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
659#endif
660#undef DECLS
Richard Trieu48143742017-02-28 21:24:38 +0000661} // namespace Method
662
Richard Trieu1c71d512017-07-15 02:55:13 +0000663namespace Constructor {
664#if defined(FIRST)
665struct S1 {
666 S1() {}
667 void foo() {}
668};
669#elif defined(SECOND)
670struct S1 {
671 void foo() {}
672 S1() {}
673};
674#else
675S1 s1;
676// expected-error@second.h:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}}
677// expected-note@first.h:* {{but in 'FirstModule' found constructor}}
678#endif
679
680#if defined(FIRST)
681struct S2 {
682 S2(int) {}
683 S2(int, int) {}
684};
685#elif defined(SECOND)
686struct S2 {
687 S2(int, int) {}
688 S2(int) {}
689};
690#else
691S2* s2;
692// expected-error@second.h:* {{'Constructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor that has 2 parameters}}
693// expected-note@first.h:* {{but in 'FirstModule' found constructor that has 1 parameter}}
694#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000695
696#define DECLS(CLASS) \
697 CLASS(int); \
698 CLASS(double); \
699 CLASS(int, int);
700
701#if defined(FIRST) || defined(SECOND)
702struct Valid1 {
703 DECLS(Valid1)
704};
705#else
706Valid1* v1;
707#endif
708
709#if defined(FIRST) || defined(SECOND)
710struct Invalid1 {
711 DECLS(Invalid1)
712 ACCESS
713};
714#else
715Invalid1* i1;
716// expected-error@second.h:* {{'Constructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
717// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
718#endif
719#undef DECLS
Richard Trieu1c71d512017-07-15 02:55:13 +0000720} // namespace Constructor
721
722namespace Destructor {
723#if defined(FIRST)
724struct S1 {
725 ~S1() {}
726 S1() {}
727};
728#elif defined(SECOND)
729struct S1 {
730 S1() {}
731 ~S1() {}
732};
733#else
734S1 s1;
735// expected-error@second.h:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}}
736// expected-note@first.h:* {{but in 'FirstModule' found destructor}}
737#endif
738
739#if defined(FIRST)
740struct S2 {
741 virtual ~S2() {}
742 void foo() {}
743};
744#elif defined(SECOND)
745struct S2 {
746 ~S2() {}
747 virtual void foo() {}
748};
749#else
750S2 s2;
751// expected-error@second.h:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}}
752// expected-note@first.h:* {{but in 'FirstModule' found destructor is virtual}}
753#endif
754
Richard Trieu73cf9242017-11-04 01:20:50 +0000755#if defined(FIRST) || defined(SECOND)
756struct Valid1 {
757 ~Valid1();
Richard Trieue7f7ed22017-02-22 01:11:25 +0000758};
Richard Trieu73cf9242017-11-04 01:20:50 +0000759#else
760Valid1 v1;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000761#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000762
763#if defined(FIRST) || defined(SECOND)
764struct Invalid1 {
765 ~Invalid1();
766 ACCESS
767};
768#else
769Invalid1 i1;
770// expected-error@second.h:* {{'Destructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
771// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
772#endif
773
774#if defined(FIRST) || defined(SECOND)
775struct Valid2 {
776 virtual ~Valid2();
777};
778#else
779Valid2 v2;
780#endif
781
782#if defined(FIRST) || defined(SECOND)
783struct Invalid2 {
784 virtual ~Invalid2();
785 ACCESS
786};
787#else
788Invalid2 i2;
789// expected-error@second.h:* {{'Destructor::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
790// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
791#endif
792} // namespace Destructor
Richard Trieue7f7ed22017-02-22 01:11:25 +0000793
Richard Trieu33562c22017-03-08 00:13:19 +0000794namespace TypeDef {
795#if defined(FIRST)
796struct S1 {
797 typedef int a;
798};
799#elif defined(SECOND)
800struct S1 {
801 typedef double a;
802};
803#else
804S1 s1;
805// expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
806// expected-note@second.h:* {{declaration of 'a' does not match}}
807#endif
808
809#if defined(FIRST)
810struct S2 {
811 typedef int a;
812};
813#elif defined(SECOND)
814struct S2 {
815 typedef int b;
816};
817#else
818S2 s2;
819// expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
820// expected-note@second.h:* {{definition has no member 'a'}}
821#endif
822
823#if defined(FIRST)
824typedef int T;
825struct S3 {
826 typedef T a;
827};
828#elif defined(SECOND)
829typedef double T;
830struct S3 {
831 typedef T a;
832};
833#else
834S3 s3;
835// expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
836// expected-note@second.h:* {{declaration of 'a' does not match}}
837#endif
Richard Trieu11d566a2017-06-12 21:58:22 +0000838
839#if defined(FIRST)
840struct S4 {
841 typedef int a;
842 typedef int b;
843};
844#elif defined(SECOND)
845struct S4 {
846 typedef int b;
847 typedef int a;
848};
849#else
850S4 s4;
851// expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}}
852// expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}}
853#endif
854
855#if defined(FIRST)
856struct S5 {
857 typedef int a;
858 typedef int b;
859 int x;
860};
861#elif defined(SECOND)
862struct S5 {
863 int x;
864 typedef int b;
865 typedef int a;
866};
867#else
868S5 s5;
869// expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
870// expected-note@first.h:* {{but in 'FirstModule' found typedef}}
871#endif
872
873#if defined(FIRST)
874typedef float F;
875struct S6 {
876 typedef int a;
877 typedef F b;
878};
879#elif defined(SECOND)
880struct S6 {
881 typedef int a;
882 typedef float b;
883};
884#else
885S6 s6;
886// expected-error@second.h:* {{'TypeDef::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef 'b' with underlying type 'float'}}
887// expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}}
888#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000889
890#define DECLS \
891 typedef int A; \
892 typedef double B; \
893 typedef I C;
894
895#if defined(FIRST) || defined(SECOND)
896typedef int I;
897#endif
898
899#if defined(FIRST) || defined(SECOND)
900struct Valid1 {
901 DECLS
902};
903#else
904Valid1 v1;
905#endif
906
907#if defined(FIRST) || defined(SECOND)
908struct Invalid1 {
909 DECLS
910 ACCESS
911};
912#else
913Invalid1 i1;
914// expected-error@second.h:* {{'TypeDef::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
915// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
916#endif
917#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +0000918} // namespace TypeDef
919
920namespace Using {
921#if defined(FIRST)
922struct S1 {
923 using a = int;
924};
925#elif defined(SECOND)
926struct S1 {
927 using a = double;
928};
929#else
930S1 s1;
931// expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
932// expected-note@second.h:* {{declaration of 'a' does not match}}
933#endif
934
935#if defined(FIRST)
936struct S2 {
937 using a = int;
938};
939#elif defined(SECOND)
940struct S2 {
941 using b = int;
942};
943#else
944S2 s2;
945// expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
946// expected-note@second.h:* {{definition has no member 'a'}}
947#endif
948
949#if defined(FIRST)
950typedef int T;
951struct S3 {
952 using a = T;
953};
954#elif defined(SECOND)
955typedef double T;
956struct S3 {
957 using a = T;
958};
959#else
960S3 s3;
961// expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
962// expected-note@second.h:* {{declaration of 'a' does not match}}
963#endif
Richard Trieu11d566a2017-06-12 21:58:22 +0000964
965#if defined(FIRST)
966struct S4 {
967 using a = int;
968 using b = int;
969};
970#elif defined(SECOND)
971struct S4 {
972 using b = int;
973 using a = int;
974};
975#else
976S4 s4;
977// expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}}
978// expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}}
979#endif
980
981#if defined(FIRST)
982struct S5 {
983 using a = int;
984 using b = int;
985 int x;
986};
987#elif defined(SECOND)
988struct S5 {
989 int x;
990 using b = int;
991 using a = int;
992};
993#else
994S5 s5;
995// expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
996// expected-note@first.h:* {{but in 'FirstModule' found type alias}}
997#endif
998
999#if defined(FIRST)
1000typedef float F;
1001struct S6 {
1002 using a = int;
1003 using b = F;
1004};
1005#elif defined(SECOND)
1006struct S6 {
1007 using a = int;
1008 using b = float;
1009};
1010#else
1011S6 s6;
1012// expected-error@second.h:* {{'Using::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'b' with underlying type 'float'}}
1013// expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}}
1014#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001015
1016#if defined(FIRST) || defined(SECOND)
1017using I = int;
1018#endif
1019
1020#define DECLS \
1021 using A = int; \
1022 using B = double; \
1023 using C = I;
1024
1025#if defined(FIRST) || defined(SECOND)
1026struct Valid1 {
1027 DECLS
1028};
1029#else
1030Valid1 v1;
1031#endif
1032
1033#if defined(FIRST) || defined(SECOND)
1034struct Invalid1 {
1035 DECLS
1036 ACCESS
1037};
1038#else
1039Invalid1 i1;
1040// expected-error@second.h:* {{'Using::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1041// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1042#endif
1043#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +00001044} // namespace Using
1045
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001046namespace RecordType {
1047#if defined(FIRST)
1048struct B1 {};
1049struct S1 {
1050 B1 x;
1051};
1052#elif defined(SECOND)
1053struct A1 {};
1054struct S1 {
1055 A1 x;
1056};
1057#else
1058S1 s1;
1059// expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
1060// expected-note@second.h:* {{declaration of 'x' does not match}}
1061#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001062
1063#define DECLS \
1064 Foo F;
1065
1066#if defined(FIRST) || defined(SECOND)
1067struct Foo {};
1068#endif
1069
1070#if defined(FIRST) || defined(SECOND)
1071struct Valid1 {
1072 DECLS
1073};
1074#else
1075Valid1 v1;
1076#endif
1077
1078#if defined(FIRST) || defined(SECOND)
1079struct Invalid1 {
1080 DECLS
1081 ACCESS
1082};
1083#else
1084Invalid1 i1;
1085// expected-error@second.h:* {{'RecordType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1086// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1087#endif
1088#undef DECLS
1089} // namespace RecordType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001090
1091namespace DependentType {
1092#if defined(FIRST)
1093template <class T>
1094class S1 {
1095 typename T::typeA x;
1096};
1097#elif defined(SECOND)
1098template <class T>
1099class S1 {
1100 typename T::typeB x;
1101};
1102#else
1103template<class T>
1104using U1 = S1<T>;
1105// expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
1106// expected-note@second.h:* {{declaration of 'x' does not match}}
1107#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001108
1109#define DECLS \
1110 typename T::typeA x;
1111
1112#if defined(FIRST) || defined(SECOND)
1113template <class T>
1114struct Valid1 {
1115 DECLS
1116};
1117#else
1118template <class T>
1119using V1 = Valid1<T>;
1120#endif
1121
1122#if defined(FIRST) || defined(SECOND)
1123template <class T>
1124struct Invalid1 {
1125 DECLS
1126 ACCESS
1127};
1128#else
1129template <class T>
1130using I1 = Invalid1<T>;
1131// expected-error@second.h:* {{'DependentType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1132// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1133#endif
1134#undef DECLS
1135} // namespace DependentType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001136
1137namespace ElaboratedType {
1138#if defined(FIRST)
1139namespace N1 { using type = double; }
1140struct S1 {
1141 N1::type x;
1142};
1143#elif defined(SECOND)
1144namespace N1 { using type = int; }
1145struct S1 {
1146 N1::type x;
1147};
1148#else
1149S1 s1;
1150// expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}}
1151// expected-note@second.h:* {{declaration of 'x' does not match}}
1152#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001153
1154#define DECLS \
1155 NS::type x;
1156
1157#if defined(FIRST) || defined(SECOND)
1158namespace NS { using type = float; }
1159#endif
1160
1161#if defined(FIRST) || defined(SECOND)
1162struct Valid1 {
1163 DECLS
1164};
1165#else
1166Valid1 v1;
1167#endif
1168
1169#if defined(FIRST) || defined(SECOND)
1170struct Invalid1 {
1171 DECLS
1172 ACCESS
1173};
1174#else
1175Invalid1 i1;
1176// expected-error@second.h:* {{'ElaboratedType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1177// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1178#endif
1179#undef DECLS
1180} // namespace ElaboratedType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001181
1182namespace Enum {
1183#if defined(FIRST)
1184enum A1 {};
1185struct S1 {
1186 A1 x;
1187};
1188#elif defined(SECOND)
1189enum A2 {};
1190struct S1 {
1191 A2 x;
1192};
1193#else
1194S1 s1;
1195// expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
1196// expected-note@second.h:* {{declaration of 'x' does not match}}
1197#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001198
1199#define DECLS \
1200 E e = E1;
1201
1202#if defined(FIRST) || defined(SECOND)
1203enum E { E1, E2 };
1204#endif
1205
1206#if defined(FIRST) || defined(SECOND)
1207struct Valid1 {
1208 DECLS
1209};
1210#else
1211Valid1 v1;
1212#endif
1213
1214#if defined(FIRST) || defined(SECOND)
1215struct Invalid1 {
1216 DECLS
1217 ACCESS
1218};
1219#else
1220Invalid1 i1;
1221// expected-error@second.h:* {{'Enum::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1222// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1223#endif
1224#undef DECLS
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001225}
Hans Wennborg22707762017-04-12 16:40:26 +00001226
Richard Trieuce81b192017-05-17 03:23:35 +00001227namespace NestedNamespaceSpecifier {
1228#if defined(FIRST)
1229namespace LevelA1 {
1230using Type = int;
1231}
1232
1233struct S1 {
1234 LevelA1::Type x;
1235};
1236# elif defined(SECOND)
1237namespace LevelB1 {
1238namespace LevelC1 {
1239using Type = int;
1240}
1241}
1242
1243struct S1 {
1244 LevelB1::LevelC1::Type x;
1245};
1246#else
1247S1 s1;
1248// 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')}}
1249// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
1250#endif
1251
1252#if defined(FIRST)
1253namespace LevelA2 { using Type = int; }
1254struct S2 {
1255 LevelA2::Type x;
1256};
1257# elif defined(SECOND)
1258struct S2 {
1259 int x;
1260};
1261#else
1262S2 s2;
1263// 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'}}
1264// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
1265#endif
1266
1267namespace LevelA3 { using Type = int; }
1268namespace LevelB3 { using Type = int; }
1269#if defined(FIRST)
1270struct S3 {
1271 LevelA3::Type x;
1272};
1273# elif defined(SECOND)
1274struct S3 {
1275 LevelB3::Type x;
1276};
1277#else
1278S3 s3;
1279// 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')}}
1280// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
1281#endif
1282
1283#if defined(FIRST)
1284struct TA4 { using Type = int; };
1285struct S4 {
1286 TA4::Type x;
1287};
1288# elif defined(SECOND)
1289struct TB4 { using Type = int; };
1290struct S4 {
1291 TB4::Type x;
1292};
1293#else
1294S4 s4;
1295// 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')}}
1296// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
1297#endif
1298
1299#if defined(FIRST)
1300struct T5 { using Type = int; };
1301struct S5 {
1302 T5::Type x;
1303};
1304# elif defined(SECOND)
1305namespace T5 { using Type = int; };
1306struct S5 {
1307 T5::Type x;
1308};
1309#else
1310S5 s5;
1311// 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')}}
1312// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
1313#endif
1314
1315#if defined(FIRST)
1316namespace N6 {using I = int;}
1317struct S6 {
1318 NestedNamespaceSpecifier::N6::I x;
1319};
1320# elif defined(SECOND)
1321using I = int;
1322struct S6 {
1323 ::NestedNamespaceSpecifier::I x;
1324};
1325#else
1326S6 s6;
1327// 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')}}
1328// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
1329#endif
1330
1331#if defined(FIRST)
1332template <class T, class U>
1333class S7 {
1334 typename T::type *x = {};
1335 int z = x->T::foo();
1336};
1337#elif defined(SECOND)
1338template <class T, class U>
1339class S7 {
1340 typename T::type *x = {};
1341 int z = x->U::foo();
1342};
1343#else
1344template <class T, class U>
1345using U7 = S7<T, U>;
1346// 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}}
1347// expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}}
1348#endif
1349
1350#if defined(FIRST)
1351template <class T>
1352class S8 {
1353 int x = T::template X<int>::value;
1354};
1355#elif defined(SECOND)
1356template <class T>
1357class S8 {
1358 int x = T::template Y<int>::value;
1359};
1360#else
1361template <class T>
1362using U8 = S8<T>;
1363// 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}}
1364// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
1365#endif
1366
1367#if defined(FIRST)
1368namespace N9 { using I = int; }
1369namespace O9 = N9;
1370struct S9 {
1371 O9::I x;
1372};
1373#elif defined(SECOND)
1374namespace N9 { using I = int; }
1375namespace P9 = N9;
1376struct S9 {
1377 P9::I x;
1378};
1379#else
1380S9 s9;
1381// 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')}}
1382// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
1383#endif
Richard Trieu96b41642017-07-01 02:00:05 +00001384
1385namespace N10 {
1386#if defined(FIRST)
1387inline namespace A { struct X {}; }
1388struct S10 {
1389 A::X x;
1390};
1391#elif defined(SECOND)
1392inline namespace B { struct X {}; }
1393struct S10 {
1394 B::X x;
1395};
1396#else
1397S10 s10;
1398// expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
1399// expected-note@first.h:* {{declaration of 'x' does not match}}
1400#endif
1401}
Richard Trieu73cf9242017-11-04 01:20:50 +00001402
1403#define DECLS \
1404 NS1::Type a; \
1405 NS1::NS2::Type b; \
1406 NS1::S c; \
1407 NS3::Type d;
1408
1409#if defined(FIRST) || defined(SECOND)
1410namespace NS1 {
1411 using Type = int;
1412 namespace NS2 {
1413 using Type = double;
1414 }
1415 struct S {};
Richard Trieuce81b192017-05-17 03:23:35 +00001416}
Richard Trieu73cf9242017-11-04 01:20:50 +00001417namespace NS3 = NS1;
1418#endif
1419
1420#if defined(FIRST) || defined(SECOND)
1421struct Valid1 {
1422 DECLS
1423};
1424#else
1425Valid1 v1;
1426#endif
1427
1428#if defined(FIRST) || defined(SECOND)
1429struct Invalid1 {
1430 DECLS
1431 ACCESS
1432};
1433#else
1434Invalid1 i1;
1435// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1436// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1437#endif
1438#undef DECLS
1439
1440#define DECLS \
1441 typename T::type *x = {}; \
1442 int y = x->T::foo(); \
1443 int z = U::template X<int>::value;
1444
1445#if defined(FIRST) || defined(SECOND)
1446template <class T, class U>
1447struct Valid2 {
1448 DECLS
1449};
1450#else
1451template <class T, class U>
1452using V2 = Valid2<T, U>;
1453#endif
1454
1455#if defined(FIRST) || defined(SECOND)
1456template <class T, class U>
1457struct Invalid2 {
1458 DECLS
1459 ACCESS
1460};
1461#else
1462template <class T, class U>
1463using I2 = Invalid2<T, U>;
1464// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1465// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1466#endif
1467#undef DECLS
1468} // namespace NestedNamespaceSpecifier
Richard Trieuce81b192017-05-17 03:23:35 +00001469
Richard Trieu96b49622017-05-31 00:31:58 +00001470namespace TemplateSpecializationType {
1471#if defined(FIRST)
1472template <class T1> struct U1 {};
1473struct S1 {
1474 U1<int> u;
1475};
1476#elif defined(SECOND)
1477template <class T1, class T2> struct U1 {};
1478struct S1 {
1479 U1<int, int> u;
1480};
1481#else
1482S1 s1;
1483// expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}}
1484// expected-note@second.h:* {{declaration of 'u' does not match}}
1485#endif
1486
1487#if defined(FIRST)
1488template <class T1> struct U2 {};
1489struct S2 {
1490 U2<int> u;
1491};
1492#elif defined(SECOND)
1493template <class T1> struct V1 {};
1494struct S2 {
1495 V1<int> u;
1496};
1497#else
1498S2 s2;
1499// expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}}
1500// expected-note@second.h:* {{declaration of 'u' does not match}}
1501#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001502
1503#define DECLS \
1504 OneTemplateArg<int> x; \
1505 OneTemplateArg<double> y; \
1506 OneTemplateArg<char *> z; \
1507 TwoTemplateArgs<int, int> a; \
1508 TwoTemplateArgs<double, float> b; \
1509 TwoTemplateArgs<short *, char> c;
1510
1511#if defined(FIRST) || defined(SECOND)
1512template <class T> struct OneTemplateArg {};
1513template <class T, class U> struct TwoTemplateArgs {};
1514#endif
1515
1516#if defined(FIRST) || defined(SECOND)
1517struct Valid1 {
1518DECLS
1519};
1520#else
1521Valid1 v1;
1522#endif
1523
1524#if defined(FIRST) || defined(SECOND)
1525struct Invalid1 {
1526DECLS
1527ACCESS
1528};
1529#else
1530Invalid1 i1;
1531// expected-error@second.h:* {{'TemplateSpecializationType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1532// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1533#endif
1534#undef DECLS
1535} // namespace TemplateSpecializationType
Richard Trieu96b49622017-05-31 00:31:58 +00001536
Richard Trieu3b261bb72017-06-13 22:21:18 +00001537namespace TemplateArgument {
1538#if defined(FIRST)
1539template <class> struct U1{};
1540struct S1 {
1541 U1<int> x;
1542};
1543#elif defined(SECOND)
1544template <int> struct U1{};
1545struct S1 {
1546 U1<1> x;
1547};
1548#else
1549S1 s1;
1550// expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
1551// expected-note@second.h:* {{declaration of 'x' does not match}}
1552#endif
Richard Trieu1dcb4052017-06-14 01:28:00 +00001553
1554#if defined(FIRST)
1555template <int> struct U2{};
1556struct S2 {
1557 using T = U2<2>;
1558};
1559#elif defined(SECOND)
1560template <int> struct U2{};
1561struct S2 {
1562 using T = U2<(2)>;
1563};
1564#else
1565S2 s2;
1566// expected-error@second.h:* {{'TemplateArgument::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U2<(2)>'}}
1567// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}}
1568#endif
1569
1570#if defined(FIRST)
1571template <int> struct U3{};
1572struct S3 {
1573 using T = U3<2>;
1574};
1575#elif defined(SECOND)
1576template <int> struct U3{};
1577struct S3 {
1578 using T = U3<1 + 1>;
1579};
1580#else
1581S3 s3;
1582// expected-error@second.h:* {{'TemplateArgument::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U3<1 + 1>'}}
1583// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}}
1584#endif
1585
Richard Trieuee132d62017-06-14 03:17:26 +00001586#if defined(FIRST)
1587template<class> struct T4a {};
1588template <template <class> class T> struct U4 {};
1589struct S4 {
1590 U4<T4a> x;
1591};
1592#elif defined(SECOND)
1593template<class> struct T4b {};
1594template <template <class> class T> struct U4 {};
1595struct S4 {
1596 U4<T4b> x;
1597};
1598#else
1599S4 s4;
1600// expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}}
1601// expected-note@second.h:* {{declaration of 'x' does not match}}
1602#endif
Richard Trieu8844c522017-06-30 22:40:33 +00001603
1604#if defined(FIRST)
1605template <class T> struct U5 {};
1606struct S5 {
1607 U5<int> x;
1608};
1609#elif defined(SECOND)
1610template <class T> struct U5 {};
1611struct S5 {
1612 U5<short> x;
1613};
1614#else
1615S5 s5;
1616// expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}}
1617// expected-note@second.h:* {{declaration of 'x' does not match}}
1618#endif
1619
1620#if defined(FIRST)
1621template <class T> struct U6 {};
1622struct S6 {
1623 U6<int> x;
1624 U6<short> y;
1625};
1626#elif defined(SECOND)
1627template <class T> struct U6 {};
1628struct S6 {
1629 U6<short> y;
1630 U6<int> x;
1631};
1632#else
1633S6 s6;
1634// expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
1635// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
1636#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001637
1638#define DECLS \
1639 OneClass<int> a; \
1640 OneInt<1> b; \
1641 using c = OneClass<float>; \
1642 using d = OneInt<2>; \
1643 using e = OneInt<2 + 2>; \
1644 OneTemplateClass<OneClass> f; \
1645 OneTemplateInt<OneInt> g;
1646
1647#if defined(FIRST) || defined(SECOND)
1648template <class> struct OneClass{};
1649template <int> struct OneInt{};
1650template <template <class> class> struct OneTemplateClass{};
1651template <template <int> class> struct OneTemplateInt{};
1652#endif
1653
1654#if defined(FIRST) || defined(SECOND)
1655struct Valid1 {
1656DECLS
1657};
1658#else
1659Valid1 v1;
1660#endif
1661
1662#if defined(FIRST) || defined(SECOND)
1663struct Invalid1 {
1664DECLS
1665ACCESS
1666};
1667#else
1668Invalid1 i1;
1669// expected-error@second.h:* {{'TemplateArgument::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1670// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1671#endif
1672#undef DECLS
1673} // namespace TemplateArgument
Richard Trieuee132d62017-06-14 03:17:26 +00001674
Richard Trieud9201d02017-06-15 01:35:06 +00001675namespace TemplateTypeParmType {
1676#if defined(FIRST)
1677template <class T1, class T2>
1678struct S1 {
1679 T1 x;
1680};
1681#elif defined(SECOND)
1682template <class T1, class T2>
1683struct S1 {
1684 T2 x;
1685};
1686#else
1687using TemplateTypeParmType::S1;
1688// expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}}
1689// expected-note@second.h:* {{declaration of 'x' does not match}}
1690#endif
1691
1692#if defined(FIRST)
1693template <int ...Ts>
1694struct U2 {};
1695template <int T, int U>
1696class S2 {
1697 typedef U2<U, T> type;
1698 type x;
1699};
1700#elif defined(SECOND)
1701template <int ...Ts>
1702struct U2 {};
1703template <int T, int U>
1704class S2 {
1705 typedef U2<T, U> type;
1706 type x;
1707};
1708#else
1709using TemplateTypeParmType::S2;
1710// expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
1711// expected-note@second.h:* {{declaration of 'x' does not match}}
1712// expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
1713// expected-note@second.h:* {{declaration of 'type' does not match}}
1714#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001715
1716#define DECLS \
1717 T t; \
1718 U u; \
1719 ParameterPack<T> a; \
1720 ParameterPack<T, U> b; \
1721 ParameterPack<U> c; \
1722 ParameterPack<U, T> d;
1723
1724#if defined(FIRST) || defined(SECOND)
1725template <class ...Ts> struct ParameterPack {};
1726#endif
1727
1728#if defined(FIRST) || defined(SECOND)
1729template <class T, class U>
1730struct Valid1 {
1731 DECLS
1732};
1733#else
1734using TemplateTypeParmType::Valid1;
1735#endif
1736
1737#if defined(FIRST) || defined(SECOND)
1738template <class T, class U>
1739struct Invalid1 {
1740 DECLS
1741 ACCESS
1742};
1743#else
1744using TemplateTypeParmType::Invalid1;
1745// expected-error@second.h:* {{'TemplateTypeParmType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1746// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1747#endif
1748#undef DECLS
1749} // namespace TemplateTypeParmType
Richard Trieu3b261bb72017-06-13 22:21:18 +00001750
Richard Trieu6e13ff32017-06-16 02:44:29 +00001751namespace VarDecl {
1752#if defined(FIRST)
1753struct S1 {
1754 static int x;
1755 static int y;
1756};
1757#elif defined(SECOND)
1758struct S1 {
1759 static int y;
1760 static int x;
1761};
1762#else
1763S1 s1;
1764// expected-error@second.h:* {{'VarDecl::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member with name 'y'}}
1765// expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}}
1766#endif
1767
1768#if defined(FIRST)
1769struct S2 {
1770 static int x;
1771};
1772#elif defined(SECOND)
1773using I = int;
1774struct S2 {
1775 static I x;
1776};
1777#else
1778S2 s2;
1779// expected-error@second.h:* {{'VarDecl::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with type 'VarDecl::I' (aka 'int')}}
1780// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}}
1781#endif
1782
1783#if defined(FIRST)
1784struct S3 {
1785 static const int x = 1;
1786};
1787#elif defined(SECOND)
1788struct S3 {
1789 static const int x;
1790};
1791#else
1792S3 s3;
1793// expected-error@second.h:* {{'VarDecl::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with an initializer}}
1794// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}}
1795#endif
1796
1797#if defined(FIRST)
1798struct S4 {
1799 static const int x = 1;
1800};
1801#elif defined(SECOND)
1802struct S4 {
1803 static const int x = 2;
1804};
1805#else
1806S4 s4;
1807// expected-error@second.h:* {{'VarDecl::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' with an initializer}}
1808// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}}
1809#endif
1810
1811#if defined(FIRST)
1812struct S5 {
1813 static const int x = 1;
1814};
1815#elif defined(SECOND)
1816struct S5 {
1817 static constexpr int x = 1;
1818};
1819#else
1820S5 s5;
1821// expected-error@second.h:* {{'VarDecl::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member 'x' is not constexpr}}
1822// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}}
1823#endif
1824
1825#if defined(FIRST)
1826struct S6 {
1827 static const int x = 1;
1828};
1829#elif defined(SECOND)
1830struct S6 {
1831 static const int y = 1;
1832};
1833#else
1834S6 s6;
1835// expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}}
1836// expected-note@second.h:* {{definition has no member 'x'}}
1837#endif
1838
1839#if defined(FIRST)
1840struct S7 {
1841 static const int x = 1;
1842};
1843#elif defined(SECOND)
1844struct S7 {
1845 static const unsigned x = 1;
1846};
1847#else
1848S7 s7;
1849// expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}}
1850// expected-note@second.h:* {{declaration of 'x' does not match}}
1851#endif
1852
1853#if defined(FIRST)
1854struct S8 {
1855public:
1856 static const int x = 1;
1857};
1858#elif defined(SECOND)
1859struct S8 {
1860 static const int x = 1;
1861public:
1862};
1863#else
1864S8 s8;
1865// expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}}
1866// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1867#endif
1868
1869#if defined(FIRST)
1870struct S9 {
1871 static const int x = 1;
1872};
1873#elif defined(SECOND)
1874struct S9 {
1875 static int x;
1876};
1877#else
1878S9 s9;
1879// expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}}
1880// expected-note@second.h:* {{declaration of 'x' does not match}}
1881#endif
1882
Richard Trieu73cf9242017-11-04 01:20:50 +00001883#define DECLS \
1884 static int a; \
1885 static I b; \
1886 static const int c = 1; \
1887 static constexpr int d = 5;
1888
1889#if defined(FIRST) || defined(SECOND)
1890using I = int;
Richard Trieu6e13ff32017-06-16 02:44:29 +00001891#endif
1892
Richard Trieu73cf9242017-11-04 01:20:50 +00001893#if defined(FIRST) || defined(SECOND)
1894struct Valid1 {
1895 DECLS
Richard Trieu6e13ff32017-06-16 02:44:29 +00001896};
Richard Trieu6e13ff32017-06-16 02:44:29 +00001897#else
Richard Trieu73cf9242017-11-04 01:20:50 +00001898Valid1 v1;
Richard Trieu6e13ff32017-06-16 02:44:29 +00001899#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001900
1901#if defined(FIRST) || defined(SECOND)
1902struct Invalid1 {
1903 DECLS
1904 ACCESS
1905};
1906#else
1907Invalid1 i1;
1908// expected-error@second.h:* {{'VarDecl::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1909// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1910#endif
1911#undef DECLS
1912} // namespace VarDecl
Richard Trieu6e13ff32017-06-16 02:44:29 +00001913
Richard Trieuac6a1b62017-07-08 02:04:42 +00001914namespace Friend {
1915#if defined(FIRST)
1916struct T1 {};
1917struct S1 {
1918 friend class T1;
1919};
1920#elif defined(SECOND)
1921struct T1 {};
1922struct S1 {
1923 friend T1;
1924};
1925#else
1926S1 s1;
1927// expected-error@second.h:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T1'}}
1928// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T1'}}
1929#endif
1930
1931#if defined(FIRST)
1932struct T2 {};
1933struct S2 {
1934 friend class T2;
1935};
1936#elif defined(SECOND)
1937struct T2 {};
1938struct S2 {
1939 friend struct T2;
1940};
1941#else
1942S2 s2;
1943// expected-error@second.h:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}}
1944// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T2'}}
1945#endif
1946
1947#if defined(FIRST)
1948struct T3 {};
1949struct S3 {
1950 friend const T3;
1951};
1952#elif defined(SECOND)
1953struct T3 {};
1954struct S3 {
1955 friend T3;
1956};
1957#else
1958S3 s3;
1959// expected-error@second.h:* {{'Friend::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T3'}}
1960// expected-note@first.h:* {{but in 'FirstModule' found friend 'const Friend::T3'}}
1961#endif
1962
1963#if defined(FIRST)
1964struct T4 {};
1965struct S4 {
1966 friend T4;
1967};
1968#elif defined(SECOND)
1969struct S4 {
1970 friend void T4();
1971};
1972#else
1973S4 s4;
1974// expected-error@second.h:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}}
1975// expected-note@first.h:* {{but in 'FirstModule' found friend class}}
1976#endif
1977
1978#if defined(FIRST)
1979struct S5 {
1980 friend void T5a();
1981};
1982#elif defined(SECOND)
1983struct S5 {
1984 friend void T5b();
1985};
1986#else
1987S5 s5;
1988// expected-error@second.h:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}}
1989// expected-note@first.h:* {{but in 'FirstModule' found friend function 'T5a'}}
1990#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001991
1992#define DECLS \
1993 friend class FriendA; \
1994 friend struct FriendB; \
1995 friend FriendC; \
1996 friend const FriendD; \
1997 friend void Function();
1998
1999#if defined(FIRST) || defined(SECOND)
2000class FriendA {};
2001class FriendB {};
2002class FriendC {};
2003class FriendD {};
2004#endif
2005
2006#if defined(FIRST) || defined(SECOND)
2007struct Valid1 {
2008 DECLS
2009};
2010#else
2011Valid1 v1;
2012#endif
2013
2014#if defined(FIRST) || defined(SECOND)
2015struct Invalid1 {
2016 DECLS
2017 ACCESS
2018};
2019#else
2020Invalid1 i1;
2021// expected-error@second.h:* {{'Friend::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2022// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2023#endif
2024#undef DECLS
2025} // namespace Friend
Richard Trieu498117b2017-08-23 02:43:59 +00002026
2027namespace TemplateParameters {
2028#if defined(FIRST)
2029template <class A>
2030struct S1 {};
2031#elif defined(SECOND)
2032template <class B>
2033struct S1 {};
2034#else
2035using TemplateParameters::S1;
2036// expected-error@second.h:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}}
2037// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2038#endif
2039
2040#if defined(FIRST)
2041template <class A = double>
2042struct S2 {};
2043#elif defined(SECOND)
2044template <class A = int>
2045struct S2 {};
2046#else
2047using TemplateParameters::S2;
2048// expected-error@second.h:* {{'TemplateParameters::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}}
2049// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2050#endif
2051
2052#if defined(FIRST)
2053template <class A = int>
2054struct S3 {};
2055#elif defined(SECOND)
2056template <class A>
2057struct S3 {};
2058#else
2059using TemplateParameters::S3;
2060// expected-error@second.h:* {{'TemplateParameters::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with no default argument}}
2061// expected-note@first.h:* {{but in 'FirstModule' found template parameter with default argument}}
2062#endif
2063
2064#if defined(FIRST)
2065template <int A>
2066struct S4 {};
2067#elif defined(SECOND)
2068template <int A = 2>
2069struct S4 {};
2070#else
2071using TemplateParameters::S4;
2072// expected-error@second.h:* {{'TemplateParameters::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}}
2073// expected-note@first.h:* {{but in 'FirstModule' found template parameter with no default argument}}
2074#endif
2075
2076#if defined(FIRST)
2077template <int> class S5_first {};
2078template <template<int> class A = S5_first>
2079struct S5 {};
2080#elif defined(SECOND)
2081template <int> class S5_second {};
2082template <template<int> class A = S5_second>
2083struct S5 {};
2084#else
2085using TemplateParameters::S5;
2086// expected-error@second.h:* {{'TemplateParameters::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}}
2087// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2088#endif
2089
2090#if defined(FIRST)
2091template <class A>
2092struct S6 {};
2093#elif defined(SECOND)
2094template <class>
2095struct S6 {};
2096#else
2097using TemplateParameters::S6;
2098// expected-error@second.h:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}}
2099// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2100#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002101
2102#define DECLS
2103
2104#if defined(FIRST) || defined(SECOND)
2105template <class> class DefaultArg;
2106#endif
2107
2108#if defined(FIRST) || defined(SECOND)
2109template <int, class, template <class> class,
2110 int A, class B, template <int> class C,
2111 int D = 1, class E = int, template <class F> class = DefaultArg>
2112struct Valid1 {
2113 DECLS
2114};
2115#else
2116using TemplateParameters::Valid1;
2117#endif
2118
2119#if defined(FIRST) || defined(SECOND)
2120template <int, class, template <class> class,
2121 int A, class B, template <int> class C,
2122 int D = 1, class E = int, template <class F> class = DefaultArg>
2123struct Invalid1 {
2124 DECLS
2125 ACCESS
2126};
2127#else
2128using TemplateParameters::Invalid1;
2129// expected-error@second.h:* {{'TemplateParameters::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2130// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2131#endif
2132#undef DECLS
Richard Trieu498117b2017-08-23 02:43:59 +00002133} // namespace TemplateParameters
2134
Richard Trieue13eabe2017-09-30 02:19:17 +00002135namespace BaseClass {
2136#if defined(FIRST)
2137struct B1 {};
2138struct S1 : B1 {};
2139#elif defined(SECOND)
2140struct S1 {};
2141#else
2142S1 s1;
2143// expected-error@second.h:* {{'BaseClass::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 base classes}}
2144// expected-note@first.h:* {{but in 'FirstModule' found 1 base class}}
2145#endif
2146
2147#if defined(FIRST)
2148struct S2 {};
2149#elif defined(SECOND)
2150struct B2 {};
2151struct S2 : virtual B2 {};
2152#else
2153S2 s2;
2154// expected-error@second.h:* {{'BaseClass::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 base class}}
2155// expected-note@first.h:* {{but in 'FirstModule' found 0 base classes}}
2156#endif
2157
2158#if defined(FIRST)
2159struct B3a {};
2160struct S3 : B3a {};
2161#elif defined(SECOND)
2162struct B3b {};
2163struct S3 : virtual B3b {};
2164#else
2165S3 s3;
2166// expected-error@second.h:* {{'BaseClass::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2167// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2168#endif
2169
2170#if defined(FIRST)
2171struct B4a {};
2172struct S4 : B4a {};
2173#elif defined(SECOND)
2174struct B4b {};
2175struct S4 : B4b {};
2176#else
2177S4 s4;
2178// expected-error@second.h:* {{'BaseClass::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class with type 'BaseClass::B4b'}}
2179// expected-note@first.h:* {{but in 'FirstModule' found 1st base class with different type 'BaseClass::B4a'}}
2180#endif
2181
2182#if defined(FIRST)
2183struct B5a {};
2184struct S5 : virtual B5a {};
2185#elif defined(SECOND)
2186struct B5a {};
2187struct S5 : B5a {};
2188#else
2189S5 s5;
2190// expected-error@second.h:* {{'BaseClass::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 virtual base classes}}
2191// expected-note@first.h:* {{but in 'FirstModule' found 1 virtual base class}}
2192#endif
2193
2194#if defined(FIRST)
2195struct B6a {};
2196struct S6 : B6a {};
2197#elif defined(SECOND)
2198struct B6a {};
2199struct S6 : virtual B6a {};
2200#else
2201S6 s6;
2202// expected-error@second.h:* {{'BaseClass::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2203// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2204#endif
2205
2206#if defined(FIRST)
2207struct B7a {};
2208struct S7 : protected B7a {};
2209#elif defined(SECOND)
2210struct B7a {};
2211struct S7 : B7a {};
2212#else
2213S7 s7;
2214// expected-error@second.h:* {{'BaseClass::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'BaseClass::B7a' with no access specifier}}
2215// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B7a' with protected access specifier}}
2216#endif
2217
2218#if defined(FIRST)
2219struct B8a {};
2220struct S8 : public B8a {};
2221#elif defined(SECOND)
2222struct B8a {};
2223struct S8 : private B8a {};
2224#else
2225S8 s8;
2226// expected-error@second.h:* {{'BaseClass::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'BaseClass::B8a' with private access specifier}}
2227// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B8a' with public access specifier}}
2228#endif
2229
2230#if defined(FIRST)
2231struct B9a {};
2232struct S9 : private B9a {};
2233#elif defined(SECOND)
2234struct B9a {};
2235struct S9 : public B9a {};
2236#else
2237S9 s9;
2238// expected-error@second.h:* {{'BaseClass::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'BaseClass::B9a' with public access specifier}}
2239// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B9a' with private access specifier}}
2240#endif
2241
2242#if defined(FIRST)
2243struct B10a {};
2244struct S10 : B10a {};
2245#elif defined(SECOND)
2246struct B10a {};
2247struct S10 : protected B10a {};
2248#else
2249S10 s10;
2250// expected-error@second.h:* {{'BaseClass::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'BaseClass::B10a' with protected access specifier}}
2251// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B10a' with no access specifier}}
2252#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002253
2254#define DECLS
2255
2256#if defined(FIRST) || defined(SECOND)
2257struct Base1 {};
2258struct Base2 {};
2259struct Base3 {};
2260struct Base4 {};
2261struct Base5 {};
2262#endif
2263
2264#if defined(FIRST) || defined(SECOND)
2265struct Valid1 :
2266 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2267
2268 DECLS
2269};
2270#else
2271Valid1 v1;
2272#endif
2273
2274#if defined(FIRST) || defined(SECOND)
2275struct Invalid1 :
2276 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2277
2278 DECLS
2279 ACCESS
2280};
2281#else
2282Invalid1 i1;
2283// expected-error@second.h:* {{'BaseClass::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2284// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2285#endif
2286#undef DECLS
Richard Trieue13eabe2017-09-30 02:19:17 +00002287} // namespace BaseClass
2288
Richard Trieu73cf9242017-11-04 01:20:50 +00002289
2290// Collection of interesting cases below.
2291
2292// Naive parsing of AST can lead to cycles in processing. Ensure
2293// self-references don't trigger an endless cycles of AST node processing.
2294namespace SelfReference {
2295#if defined(FIRST)
2296template <template <int> class T> class Wrapper {};
2297
2298template <int N> class S {
2299 S(Wrapper<::SelfReference::S> &Ref) {}
2300};
2301
2302struct Xx {
2303 struct Yy {
Richard Trieufe564052017-04-20 02:53:53 +00002304 };
Richard Trieu73cf9242017-11-04 01:20:50 +00002305};
Richard Trieufe564052017-04-20 02:53:53 +00002306
Richard Trieu73cf9242017-11-04 01:20:50 +00002307Xx::Xx::Xx::Yy yy;
Richard Trieue7f7ed22017-02-22 01:11:25 +00002308
Richard Trieu73cf9242017-11-04 01:20:50 +00002309namespace NNS {
2310template <typename> struct Foo;
2311template <template <class> class T = NNS::Foo>
2312struct NestedNamespaceSpecifier {};
Richard Trieue7f7ed22017-02-22 01:11:25 +00002313}
Richard Trieu73cf9242017-11-04 01:20:50 +00002314#endif
2315} // namespace SelfReference
Richard Trieue7f7ed22017-02-22 01:11:25 +00002316
2317namespace FriendFunction {
2318#if defined(FIRST)
2319void F(int = 0);
2320struct S { friend void F(int); };
2321#elif defined(SECOND)
2322void F(int);
2323struct S { friend void F(int); };
2324#else
2325S s;
2326#endif
2327
2328#if defined(FIRST)
2329void G(int = 0);
2330struct T {
2331 friend void G(int);
2332
2333 private:
2334};
2335#elif defined(SECOND)
2336void G(int);
2337struct T {
2338 friend void G(int);
2339
2340 public:
2341};
2342#else
2343T t;
2344// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2345// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
2346#endif
2347} // namespace FriendFunction
2348
2349namespace ImplicitDecl {
2350#if defined(FIRST)
2351struct S { };
2352void S_Constructors() {
2353 // Trigger creation of implicit contructors
2354 S foo;
2355 S bar = foo;
2356 S baz(bar);
2357}
2358#elif defined(SECOND)
2359struct S { };
2360#else
2361S s;
2362#endif
2363
2364#if defined(FIRST)
2365struct T {
2366 private:
2367};
2368void T_Constructors() {
2369 // Trigger creation of implicit contructors
2370 T foo;
2371 T bar = foo;
2372 T baz(bar);
2373}
2374#elif defined(SECOND)
2375struct T {
2376 public:
2377};
2378#else
2379T t;
2380// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
2381// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
2382#endif
2383
Richard Trieu73cf9242017-11-04 01:20:50 +00002384} // namespace ImplicitDecl
Richard Trieue7f7ed22017-02-22 01:11:25 +00002385
2386namespace TemplatedClass {
2387#if defined(FIRST)
2388template <class>
2389struct S {};
2390#elif defined(SECOND)
2391template <class>
2392struct S {};
2393#else
2394S<int> s;
2395#endif
2396
2397#if defined(FIRST)
2398template <class>
2399struct T {
2400 private:
2401};
2402#elif defined(SECOND)
2403template <class>
2404struct T {
2405 public:
2406};
2407#else
2408T<int> t;
2409// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2410// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
2411#endif
2412} // namespace TemplatedClass
2413
2414namespace TemplateClassWithField {
2415#if defined(FIRST)
2416template <class A>
2417struct S {
2418 A a;
2419};
2420#elif defined(SECOND)
2421template <class A>
2422struct S {
2423 A a;
2424};
2425#else
2426S<int> s;
2427#endif
2428
2429#if defined(FIRST)
2430template <class A>
2431struct T {
2432 A a;
2433
2434 private:
2435};
2436#elif defined(SECOND)
2437template <class A>
2438struct T {
2439 A a;
2440
2441 public:
2442};
2443#else
2444T<int> t;
2445// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2446// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
2447#endif
2448} // namespace TemplateClassWithField
2449
2450namespace TemplateClassWithTemplateField {
2451#if defined(FIRST)
2452template <class A>
2453class WrapperS;
2454template <class A>
2455struct S {
2456 WrapperS<A> a;
2457};
2458#elif defined(SECOND)
2459template <class A>
2460class WrapperS;
2461template <class A>
2462struct S {
2463 WrapperS<A> a;
2464};
2465#else
2466template <class A>
2467class WrapperS{};
2468S<int> s;
2469#endif
2470
2471#if defined(FIRST)
2472template <class A>
2473class WrapperT;
2474template <class A>
2475struct T {
2476 WrapperT<A> a;
2477
2478 public:
2479};
2480#elif defined(SECOND)
2481template <class A>
2482class WrapperT;
2483template <class A>
2484struct T {
2485 WrapperT<A> a;
2486
2487 private:
2488};
2489#else
2490template <class A>
2491class WrapperT{};
2492T<int> t;
2493// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2494// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2495#endif
2496} // namespace TemplateClassWithTemplateField
2497
2498namespace EnumWithForwardDeclaration {
2499#if defined(FIRST)
2500enum E : int;
2501struct S {
2502 void get(E) {}
2503};
2504#elif defined(SECOND)
2505enum E : int { A, B };
2506struct S {
2507 void get(E) {}
2508};
2509#else
2510S s;
2511#endif
2512
2513#if defined(FIRST)
2514struct T {
2515 void get(E) {}
2516 public:
2517};
2518#elif defined(SECOND)
2519struct T {
2520 void get(E) {}
2521 private:
2522};
2523#else
2524T t;
2525// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2526// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2527#endif
2528} // namespace EnumWithForwardDeclaration
2529
2530namespace StructWithForwardDeclaration {
2531#if defined(FIRST)
2532struct P {};
2533struct S {
2534 struct P *ptr;
2535};
2536#elif defined(SECOND)
2537struct S {
2538 struct P *ptr;
2539};
2540#else
2541S s;
2542#endif
2543
2544#if defined(FIRST)
2545struct Q {};
2546struct T {
2547 struct Q *ptr;
2548 public:
2549};
2550#elif defined(SECOND)
2551struct T {
2552 struct Q *ptr;
2553 private:
2554};
2555#else
2556T t;
2557// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2558// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2559#endif
2560} // namespace StructWithForwardDeclaration
2561
2562namespace StructWithForwardDeclarationNoDefinition {
2563#if defined(FIRST)
2564struct P;
2565struct S {
2566 struct P *ptr;
2567};
2568#elif defined(SECOND)
2569struct S {
2570 struct P *ptr;
2571};
2572#else
2573S s;
2574#endif
2575
2576#if defined(FIRST)
2577struct Q;
2578struct T {
2579 struct Q *ptr;
2580
2581 public:
2582};
2583#elif defined(SECOND)
2584struct T {
2585 struct Q *ptr;
2586
2587 private:
2588};
2589#else
2590T t;
2591// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2592// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2593#endif
2594} // namespace StructWithForwardDeclarationNoDefinition
2595
Richard Trieufe564052017-04-20 02:53:53 +00002596namespace LateParsedDefaultArgument {
2597#if defined(FIRST)
2598template <typename T>
2599struct S {
2600 struct R {
2601 void foo(T x = 0) {}
2602 };
2603};
2604#elif defined(SECOND)
2605#else
2606void run() {
2607 S<int>::R().foo();
2608}
2609#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002610} // namespace LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00002611
2612namespace LateParsedDefaultArgument {
2613#if defined(FIRST)
2614template <typename alpha> struct Bravo {
2615 void charlie(bool delta = false) {}
2616};
2617typedef Bravo<char> echo;
2618echo foxtrot;
2619
2620Bravo<char> golf;
2621#elif defined(SECOND)
2622#else
2623#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002624} // LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00002625
Richard Trieu157ed942017-04-28 22:03:28 +00002626namespace DifferentParameterNameInTemplate {
2627#if defined(FIRST) || defined(SECOND)
2628template <typename T>
2629struct S {
2630 typedef T Type;
2631
2632 static void Run(const Type *name_one);
2633};
2634
2635template <typename T>
2636void S<T>::Run(const T *name_two) {}
2637
2638template <typename T>
2639struct Foo {
2640 ~Foo() { Handler::Run(nullptr); }
2641 Foo() {}
2642
2643 class Handler : public S<T> {};
2644
2645 void Get(typename Handler::Type *x = nullptr) {}
2646 void Add() { Handler::Run(nullptr); }
2647};
2648#endif
2649
2650#if defined(FIRST)
2651struct Beta;
2652
2653struct Alpha {
2654 Alpha();
2655 void Go() { betas.Get(); }
2656 Foo<Beta> betas;
2657};
2658
2659#elif defined(SECOND)
2660struct Beta {};
2661
2662struct BetaHelper {
2663 void add_Beta() { betas.Add(); }
2664 Foo<Beta> betas;
2665};
2666
2667#else
2668Alpha::Alpha() {}
2669#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002670} // DifferentParameterNameInTemplate
Richard Trieu157ed942017-04-28 22:03:28 +00002671
Richard Trieu02552272017-05-02 23:58:52 +00002672namespace ParameterTest {
2673#if defined(FIRST)
2674class X {};
2675template <typename G>
2676class S {
2677 public:
2678 typedef G Type;
2679 static inline G *Foo(const G *a, int * = nullptr);
2680};
2681
2682template<typename G>
2683G* S<G>::Foo(const G* aaaa, int*) {}
2684#elif defined(SECOND)
2685template <typename G>
2686class S {
2687 public:
2688 typedef G Type;
2689 static inline G *Foo(const G *a, int * = nullptr);
2690};
2691
2692template<typename G>
2693G* S<G>::Foo(const G* asdf, int*) {}
2694#else
2695S<X> s;
2696#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002697} // ParameterTest
Richard Trieu02552272017-05-02 23:58:52 +00002698
Richard Trieub35ef2a2017-05-09 03:24:34 +00002699namespace MultipleTypedefs {
2700#if defined(FIRST)
2701typedef int B1;
2702typedef B1 A1;
2703struct S1 {
2704 A1 x;
2705};
2706#elif defined(SECOND)
2707typedef int A1;
2708struct S1 {
2709 A1 x;
2710};
2711#else
2712S1 s1;
2713#endif
2714
2715#if defined(FIRST)
2716struct T2 { int x; };
2717typedef T2 B2;
2718typedef B2 A2;
2719struct S2 {
2720 T2 x;
2721};
2722#elif defined(SECOND)
2723struct T2 { int x; };
2724typedef T2 A2;
2725struct S2 {
2726 T2 x;
2727};
2728#else
2729S2 s2;
2730#endif
Richard Trieu3e03d3e2017-06-29 22:53:04 +00002731
2732#if defined(FIRST)
2733using A3 = const int;
2734using B3 = volatile A3;
2735struct S3 {
2736 B3 x = 1;
2737};
2738#elif defined(SECOND)
2739using A3 = volatile const int;
2740using B3 = A3;
2741struct S3 {
2742 B3 x = 1;
2743};
2744#else
2745S3 s3;
2746#endif
Richard Trieucaaccee2018-04-12 02:26:49 +00002747
2748#if defined(FIRST)
2749using A4 = int;
2750using B4 = A4;
2751struct S4 {
2752 B4 x;
2753};
2754#elif defined(SECOND)
2755using A4 = int;
2756using B4 = ::MultipleTypedefs::A4;
2757struct S4 {
2758 B4 x;
2759};
2760#else
2761S4 s4;
2762#endif
2763
2764#if defined(FIRST)
2765using A5 = int;
2766using B5 = MultipleTypedefs::A5;
2767struct S5 {
2768 B5 x;
2769};
2770#elif defined(SECOND)
2771using A5 = int;
2772using B5 = ::MultipleTypedefs::A5;
2773struct S5 {
2774 B5 x;
2775};
2776#else
2777S5 s5;
2778#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002779} // MultipleTypedefs
2780
2781namespace DefaultArguments {
2782#if defined(FIRST)
2783template <typename T>
2784struct S {
2785 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00002786 void foo(T x = 0);
Richard Trieu73cf9242017-11-04 01:20:50 +00002787 };
2788};
2789#elif defined(SECOND)
2790template <typename T>
2791struct S {
2792 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00002793 void foo(T x = 1);
Richard Trieu73cf9242017-11-04 01:20:50 +00002794 };
2795};
2796#else
2797void run() {
2798 S<int>::R().foo();
Richard Trieub35ef2a2017-05-09 03:24:34 +00002799}
Richard Trieu73cf9242017-11-04 01:20:50 +00002800// expected-error@second.h:* {{'DefaultArguments::S::R' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo' with 1st parameter with a default argument}}
2801// expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}}
2802#endif
2803
2804#if defined(FIRST)
2805template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00002806 void charlie(bool delta = false);
Richard Trieu73cf9242017-11-04 01:20:50 +00002807};
2808typedef Bravo<char> echo;
2809echo foxtrot;
2810#elif defined(SECOND)
2811template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00002812 void charlie(bool delta = (false));
Richard Trieu73cf9242017-11-04 01:20:50 +00002813};
2814typedef Bravo<char> echo;
2815echo foxtrot;
2816#else
2817Bravo<char> golf;
2818// expected-error@second.h:* {{'DefaultArguments::Bravo' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'charlie' with 1st parameter with a default argument}}
2819// expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}}
2820#endif
2821} // namespace DefaultArguments
Richard Trieu02552272017-05-02 23:58:52 +00002822
Richard Trieue6caa262017-12-23 00:41:01 +00002823namespace FunctionDecl {
2824#if defined(FIRST)
2825struct S1 {};
2826S1 s1a;
2827#elif defined(SECOND)
2828struct S1 {};
2829#else
2830S1 s1;
2831#endif
2832
2833#if defined(FIRST)
2834struct S2 {
2835 S2() = default;
2836};
2837S2 s2a = S2();
2838#elif defined(SECOND)
2839struct S2 {
2840 S2() = default;
2841};
2842#else
2843S2 s2;
2844#endif
2845
2846#if defined(FIRST)
2847struct S3 {
2848 S3() = delete;
2849};
2850S3* s3c;
2851#elif defined(SECOND)
2852struct S3 {
2853 S3() = delete;
2854};
2855#else
2856S3* s3;
2857#endif
2858
2859#if defined(FIRST) || defined(SECOND)
2860int F1(int x, float y = 2.7) { return 1; }
2861#else
2862int I1 = F1(1);
2863#endif
2864
2865#if defined(FIRST)
2866int F2() { return 1; }
2867#elif defined(SECOND)
2868double F2() { return 1; }
2869#else
2870int I2 = F2();
2871// expected-error@-1 {{call to 'F2' is ambiguous}}
2872// expected-note@first.h:* {{candidate function}}
2873// expected-note@second.h:* {{candidate function}}
2874#endif
2875
2876#if defined(FIRST)
2877int F3(float) { return 1; }
2878#elif defined(SECOND)
2879int F3(double) { return 1; }
2880#else
2881int I3 = F3(1);
2882// expected-error@-1 {{call to 'F3' is ambiguous}}
2883// expected-note@first.h:* {{candidate function}}
2884// expected-note@second.h:* {{candidate function}}
2885#endif
2886
2887#if defined(FIRST)
2888int F4(int x) { return 1; }
2889#elif defined(SECOND)
2890int F4(int y) { return 1; }
2891#else
2892int I4 = F4(1);
2893// expected-error@second.h:* {{'FunctionDecl::F4' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with name 'y'}}
2894// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with name 'x'}}
2895#endif
2896
2897#if defined(FIRST)
2898int F5(int x) { return 1; }
2899#elif defined(SECOND)
2900int F5(int x = 1) { return 1; }
2901#else
2902int I5 = F6(1);
2903// expected-error@second.h:* {{'FunctionDecl::F5' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter without a default argument}}
2904// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a default argument}}
2905#endif
2906
2907#if defined(FIRST)
2908int F6(int x = 2) { return 1; }
2909#elif defined(SECOND)
2910int F6(int x = 1) { return 1; }
2911#else
2912int I6 = F6(1);
2913// expected-error@second.h:* {{'FunctionDecl::F6' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with a default argument}}
2914// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a different default argument}}
2915#endif
2916
2917using I = int;
2918#if defined(FIRST)
2919I F7() { return 0; }
2920#elif defined(SECOND)
2921int F7() { return 0; }
2922#else
2923int I7 = F7();
2924// expected-error@second.h:* {{'FunctionDecl::F7' has different definitions in different modules; definition in module 'SecondModule' first difference is return type is 'int'}}
2925// expected-note@first.h:* {{but in 'FirstModule' found different return type 'FunctionDecl::I' (aka 'int')}}
2926#endif
2927
2928#if defined(FIRST)
2929int F8(int) { return 0; }
2930#elif defined(SECOND)
2931int F8(I) { return 0; }
2932#else
2933int I8 = F8(1);
2934// expected-error@second.h:* {{'FunctionDecl::F8' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with type 'FunctionDecl::I' (aka 'int')}}
2935// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int'}}
2936#endif
2937
2938#if defined(FIRST)
2939int F9(int[1]) { return 0; }
2940#elif defined(SECOND)
2941int F9(int[2]) { return 0; }
2942#else
2943int I9 = F9(nullptr);
2944// expected-error@second.h:* {{'FunctionDecl::F9' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with type 'int *' decayed from 'int [2]'}}
2945// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int *' decayed from 'int [1]'}}
2946#endif
2947
2948#if defined(FIRST)
2949int F10() { return 1; }
2950#elif defined(SECOND)
2951int F10() { return 2; }
2952#else
2953int I10 = F10();
2954#endif
2955// expected-error@second.h:* {{'FunctionDecl::F10' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
2956// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
2957} // namespace FunctionDecl
2958
Richard Trieu4d06bef2018-02-13 19:53:40 +00002959namespace DeclTemplateArguments {
2960#if defined(FIRST)
2961int foo() { return 1; }
2962int bar() { return foo(); }
2963#elif defined(SECOND)
2964template <class T = int>
2965int foo() { return 2; }
2966int bar() { return foo<>(); }
2967#else
2968int num = bar();
2969// expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
2970// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
2971#endif
2972}
2973
Richard Trieue7f7ed22017-02-22 01:11:25 +00002974// Keep macros contained to one file.
2975#ifdef FIRST
2976#undef FIRST
2977#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002978
Richard Trieue7f7ed22017-02-22 01:11:25 +00002979#ifdef SECOND
2980#undef SECOND
2981#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002982
2983#ifdef ACCESS
2984#undef ACCESS
2985#endif