blob: 117029405ea03fbd3845381a009cf2fb6d779269 [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 Trieu27c1b1a2018-07-10 01:40:50 +0000663namespace MethodBody {
664#if defined(FIRST)
665struct S1 {
666 int A() { return 0; }
667};
668#elif defined(SECOND)
669struct S1 {
670 int A() { return 0; }
671};
672#else
673S1 s1;
674#endif
675
676#if defined(FIRST)
677struct S2 {
678 int BothBodies() { return 0; }
679};
680#elif defined(SECOND)
681struct S2 {
682 int BothBodies() { return 1; }
683};
684#else
685S2 s2;
686// expected-error@first.h:* {{'MethodBody::S2' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'BothBodies' with body}}
687// expected-note@second.h:* {{but in 'SecondModule' found method 'BothBodies' with different body}}
688#endif
689
690#if defined(FIRST)
691struct S3 {
692 int FirstBody() { return 0; }
693};
694#elif defined(SECOND)
695struct S3 {
696 int FirstBody();
697};
698#else
699S3 s3;
700// expected-error@first.h:* {{'MethodBody::S3' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstBody' with body}}
701// expected-note@second.h:* {{but in 'SecondModule' found method 'FirstBody' with no body}}
702#endif
703
704#if defined(FIRST)
705struct S4 {
706 int SecondBody();
707};
708#elif defined(SECOND)
709struct S4 {
710 int SecondBody() { return 0; }
711};
712#else
713S4 s4;
714// expected-error@first.h:* {{'MethodBody::S4' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'SecondBody' with no body}}
715// expected-note@second.h:* {{but in 'SecondModule' found method 'SecondBody' with body}}
716#endif
717
718#if defined(FIRST)
719struct S5 {
720 int FirstBodySecondOutOfLine() { return 0; }
721};
722#elif defined(SECOND)
723struct S5 {
724 int FirstBodySecondOutOfLine();
725};
726int S5::FirstBodySecondOutOfLine() { return 0; }
727#else
728S5 s5;
729// expected-error@second.h:* {{'MethodBody::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'FirstBodySecondOutOfLine' with no body}}
730// expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}}
731#endif
732
733#if defined(FIRST)
734struct S6 {
735 int FirstOutOfLineSecondBody();
736};
737int S6::FirstOutOfLineSecondBody() { return 0; }
738#elif defined(SECOND)
739struct S6 {
740 int FirstOutOfLineSecondBody() { return 0; }
741};
742#else
743S6 s6;
744// expected-error@first.h:* {{'MethodBody::S6' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstOutOfLineSecondBody' with no body}}
745// expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}}
746#endif
747
748#if defined(FIRST)
749struct S7 {
750 int BothOutOfLine();
751};
752int S7::BothOutOfLine() { return 1; }
753#elif defined(SECOND)
754struct S7 {
755 int BothOutOfLine();
756};
757int S7::BothOutOfLine() { return 0; }
758#else
759S7 s7;
760// expected-error@second.h:* {{'MethodBody::S7::BothOutOfLine' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
761// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
762#endif
763
764#if defined(FIRST)
765struct S8 {
766 int FirstBodySecondOutOfLine() { return 0; }
767};
768#elif defined(SECOND)
769struct S8 {
770 int FirstBodySecondOutOfLine();
771};
772int S8::FirstBodySecondOutOfLine() { return 1; }
773#else
774S8 s8;
775// expected-error@second.h:* {{'MethodBody::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'FirstBodySecondOutOfLine' with no body}}
776// expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}}
777#endif
778
779#if defined(FIRST)
780struct S9 {
781 int FirstOutOfLineSecondBody();
782};
783int S9::FirstOutOfLineSecondBody() { return 1; }
784#elif defined(SECOND)
785struct S9 {
786 int FirstOutOfLineSecondBody() { return 0; }
787};
788#else
789S9 s9;
790// expected-error@first.h:* {{'MethodBody::S9' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstOutOfLineSecondBody' with no body}}
791// expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}}
792#endif
793
794#if defined(FIRST)
795struct S10 {
796 S10(int);
797 S10() = delete;
798};
799#elif defined(SECOND)
800struct S10 {
801 S10(int);
802 S10();
803};
804#else
805S10 s10(10);
806// expected-error@first.h:* {{'MethodBody::S10' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is deleted}}
807// expected-note@second.h:* {{but in 'SecondModule' found constructor is not deleted}}
808#endif
809
810#if defined(FIRST)
811struct S11 {
812 S11() = default;
813};
814#elif defined(SECOND)
815struct S11 {
816 S11();
817};
818#else
819S11 s11;
820// expected-error@first.h:* {{'MethodBody::S11' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is defaulted}}
821// expected-note@second.h:* {{but in 'SecondModule' found constructor is not defaulted}}
822#endif
823
824#define DECLS(CLASSNAME) \
825 CLASSNAME() = default; \
826 ~CLASSNAME() = delete; \
827 void A(); \
828 void B() { return; }; \
829 void C(); \
830 void D();
831
832#define OUTOFLINEDEFS(CLASSNAME) \
833 void CLASSNAME::C() {} \
834 void CLASSNAME::D() { return; }
835
836#if defined(FIRST) || defined(SECOND)
837struct Valid1 {
838 DECLS(Valid1)
839};
840OUTOFLINEDEFS(Valid1)
841#else
842Valid1* v1;
843#endif
844
845#if defined(FIRST) || defined(SECOND)
846struct Invalid1 {
847 DECLS(Invalid1)
848 ACCESS
849};
850OUTOFLINEDEFS(Invalid1)
851#else
852Invalid1* i1;
853// expected-error@first.h:* {{'MethodBody::Invalid1' has different definitions in different modules; first difference is definition in module 'FirstModule' found public access specifier}}
854// expected-note@second.h:* {{but in 'SecondModule' found private access specifier}}
855#endif
856#undef DECLS
857} // namespace MethodBody
858
Richard Trieu1c71d512017-07-15 02:55:13 +0000859namespace Constructor {
860#if defined(FIRST)
861struct S1 {
862 S1() {}
863 void foo() {}
864};
865#elif defined(SECOND)
866struct S1 {
867 void foo() {}
868 S1() {}
869};
870#else
871S1 s1;
872// expected-error@second.h:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}}
873// expected-note@first.h:* {{but in 'FirstModule' found constructor}}
874#endif
875
876#if defined(FIRST)
877struct S2 {
878 S2(int) {}
879 S2(int, int) {}
880};
881#elif defined(SECOND)
882struct S2 {
883 S2(int, int) {}
884 S2(int) {}
885};
886#else
887S2* s2;
888// 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}}
889// expected-note@first.h:* {{but in 'FirstModule' found constructor that has 1 parameter}}
890#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000891
892#define DECLS(CLASS) \
893 CLASS(int); \
894 CLASS(double); \
895 CLASS(int, int);
896
897#if defined(FIRST) || defined(SECOND)
898struct Valid1 {
899 DECLS(Valid1)
900};
901#else
902Valid1* v1;
903#endif
904
905#if defined(FIRST) || defined(SECOND)
906struct Invalid1 {
907 DECLS(Invalid1)
908 ACCESS
909};
910#else
911Invalid1* i1;
912// expected-error@second.h:* {{'Constructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
913// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
914#endif
915#undef DECLS
Richard Trieu1c71d512017-07-15 02:55:13 +0000916} // namespace Constructor
917
918namespace Destructor {
919#if defined(FIRST)
920struct S1 {
921 ~S1() {}
922 S1() {}
923};
924#elif defined(SECOND)
925struct S1 {
926 S1() {}
927 ~S1() {}
928};
929#else
930S1 s1;
931// expected-error@second.h:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}}
932// expected-note@first.h:* {{but in 'FirstModule' found destructor}}
933#endif
934
935#if defined(FIRST)
936struct S2 {
937 virtual ~S2() {}
938 void foo() {}
939};
940#elif defined(SECOND)
941struct S2 {
942 ~S2() {}
943 virtual void foo() {}
944};
945#else
946S2 s2;
947// expected-error@second.h:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}}
948// expected-note@first.h:* {{but in 'FirstModule' found destructor is virtual}}
949#endif
950
Richard Trieu73cf9242017-11-04 01:20:50 +0000951#if defined(FIRST) || defined(SECOND)
952struct Valid1 {
953 ~Valid1();
Richard Trieue7f7ed22017-02-22 01:11:25 +0000954};
Richard Trieu73cf9242017-11-04 01:20:50 +0000955#else
956Valid1 v1;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000957#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000958
959#if defined(FIRST) || defined(SECOND)
960struct Invalid1 {
961 ~Invalid1();
962 ACCESS
963};
964#else
965Invalid1 i1;
966// expected-error@second.h:* {{'Destructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
967// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
968#endif
969
970#if defined(FIRST) || defined(SECOND)
971struct Valid2 {
972 virtual ~Valid2();
973};
974#else
975Valid2 v2;
976#endif
977
978#if defined(FIRST) || defined(SECOND)
979struct Invalid2 {
980 virtual ~Invalid2();
981 ACCESS
982};
983#else
984Invalid2 i2;
985// expected-error@second.h:* {{'Destructor::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
986// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
987#endif
988} // namespace Destructor
Richard Trieue7f7ed22017-02-22 01:11:25 +0000989
Richard Trieu33562c22017-03-08 00:13:19 +0000990namespace TypeDef {
991#if defined(FIRST)
992struct S1 {
993 typedef int a;
994};
995#elif defined(SECOND)
996struct S1 {
997 typedef double a;
998};
999#else
1000S1 s1;
1001// expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
1002// expected-note@second.h:* {{declaration of 'a' does not match}}
1003#endif
1004
1005#if defined(FIRST)
1006struct S2 {
1007 typedef int a;
1008};
1009#elif defined(SECOND)
1010struct S2 {
1011 typedef int b;
1012};
1013#else
1014S2 s2;
1015// expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
1016// expected-note@second.h:* {{definition has no member 'a'}}
1017#endif
1018
1019#if defined(FIRST)
1020typedef int T;
1021struct S3 {
1022 typedef T a;
1023};
1024#elif defined(SECOND)
1025typedef double T;
1026struct S3 {
1027 typedef T a;
1028};
1029#else
1030S3 s3;
1031// expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
1032// expected-note@second.h:* {{declaration of 'a' does not match}}
1033#endif
Richard Trieu11d566a2017-06-12 21:58:22 +00001034
1035#if defined(FIRST)
1036struct S4 {
1037 typedef int a;
1038 typedef int b;
1039};
1040#elif defined(SECOND)
1041struct S4 {
1042 typedef int b;
1043 typedef int a;
1044};
1045#else
1046S4 s4;
1047// expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}}
1048// expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}}
1049#endif
1050
1051#if defined(FIRST)
1052struct S5 {
1053 typedef int a;
1054 typedef int b;
1055 int x;
1056};
1057#elif defined(SECOND)
1058struct S5 {
1059 int x;
1060 typedef int b;
1061 typedef int a;
1062};
1063#else
1064S5 s5;
1065// expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
1066// expected-note@first.h:* {{but in 'FirstModule' found typedef}}
1067#endif
1068
1069#if defined(FIRST)
1070typedef float F;
1071struct S6 {
1072 typedef int a;
1073 typedef F b;
1074};
1075#elif defined(SECOND)
1076struct S6 {
1077 typedef int a;
1078 typedef float b;
1079};
1080#else
1081S6 s6;
1082// 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'}}
1083// expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}}
1084#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001085
1086#define DECLS \
1087 typedef int A; \
1088 typedef double B; \
1089 typedef I C;
1090
1091#if defined(FIRST) || defined(SECOND)
1092typedef int I;
1093#endif
1094
1095#if defined(FIRST) || defined(SECOND)
1096struct Valid1 {
1097 DECLS
1098};
1099#else
1100Valid1 v1;
1101#endif
1102
1103#if defined(FIRST) || defined(SECOND)
1104struct Invalid1 {
1105 DECLS
1106 ACCESS
1107};
1108#else
1109Invalid1 i1;
1110// expected-error@second.h:* {{'TypeDef::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1111// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1112#endif
1113#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +00001114} // namespace TypeDef
1115
1116namespace Using {
1117#if defined(FIRST)
1118struct S1 {
1119 using a = int;
1120};
1121#elif defined(SECOND)
1122struct S1 {
1123 using a = double;
1124};
1125#else
1126S1 s1;
1127// expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
1128// expected-note@second.h:* {{declaration of 'a' does not match}}
1129#endif
1130
1131#if defined(FIRST)
1132struct S2 {
1133 using a = int;
1134};
1135#elif defined(SECOND)
1136struct S2 {
1137 using b = int;
1138};
1139#else
1140S2 s2;
1141// expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
1142// expected-note@second.h:* {{definition has no member 'a'}}
1143#endif
1144
1145#if defined(FIRST)
1146typedef int T;
1147struct S3 {
1148 using a = T;
1149};
1150#elif defined(SECOND)
1151typedef double T;
1152struct S3 {
1153 using a = T;
1154};
1155#else
1156S3 s3;
1157// expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
1158// expected-note@second.h:* {{declaration of 'a' does not match}}
1159#endif
Richard Trieu11d566a2017-06-12 21:58:22 +00001160
1161#if defined(FIRST)
1162struct S4 {
1163 using a = int;
1164 using b = int;
1165};
1166#elif defined(SECOND)
1167struct S4 {
1168 using b = int;
1169 using a = int;
1170};
1171#else
1172S4 s4;
1173// expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}}
1174// expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}}
1175#endif
1176
1177#if defined(FIRST)
1178struct S5 {
1179 using a = int;
1180 using b = int;
1181 int x;
1182};
1183#elif defined(SECOND)
1184struct S5 {
1185 int x;
1186 using b = int;
1187 using a = int;
1188};
1189#else
1190S5 s5;
1191// expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
1192// expected-note@first.h:* {{but in 'FirstModule' found type alias}}
1193#endif
1194
1195#if defined(FIRST)
1196typedef float F;
1197struct S6 {
1198 using a = int;
1199 using b = F;
1200};
1201#elif defined(SECOND)
1202struct S6 {
1203 using a = int;
1204 using b = float;
1205};
1206#else
1207S6 s6;
1208// 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'}}
1209// expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}}
1210#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001211
1212#if defined(FIRST) || defined(SECOND)
1213using I = int;
1214#endif
1215
1216#define DECLS \
1217 using A = int; \
1218 using B = double; \
1219 using C = I;
1220
1221#if defined(FIRST) || defined(SECOND)
1222struct Valid1 {
1223 DECLS
1224};
1225#else
1226Valid1 v1;
1227#endif
1228
1229#if defined(FIRST) || defined(SECOND)
1230struct Invalid1 {
1231 DECLS
1232 ACCESS
1233};
1234#else
1235Invalid1 i1;
1236// expected-error@second.h:* {{'Using::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1237// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1238#endif
1239#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +00001240} // namespace Using
1241
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001242namespace RecordType {
1243#if defined(FIRST)
1244struct B1 {};
1245struct S1 {
1246 B1 x;
1247};
1248#elif defined(SECOND)
1249struct A1 {};
1250struct S1 {
1251 A1 x;
1252};
1253#else
1254S1 s1;
1255// expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
1256// expected-note@second.h:* {{declaration of 'x' does not match}}
1257#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001258
1259#define DECLS \
1260 Foo F;
1261
1262#if defined(FIRST) || defined(SECOND)
1263struct Foo {};
1264#endif
1265
1266#if defined(FIRST) || defined(SECOND)
1267struct Valid1 {
1268 DECLS
1269};
1270#else
1271Valid1 v1;
1272#endif
1273
1274#if defined(FIRST) || defined(SECOND)
1275struct Invalid1 {
1276 DECLS
1277 ACCESS
1278};
1279#else
1280Invalid1 i1;
1281// expected-error@second.h:* {{'RecordType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1282// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1283#endif
1284#undef DECLS
1285} // namespace RecordType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001286
1287namespace DependentType {
1288#if defined(FIRST)
1289template <class T>
1290class S1 {
1291 typename T::typeA x;
1292};
1293#elif defined(SECOND)
1294template <class T>
1295class S1 {
1296 typename T::typeB x;
1297};
1298#else
1299template<class T>
1300using U1 = S1<T>;
1301// expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
1302// expected-note@second.h:* {{declaration of 'x' does not match}}
1303#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001304
1305#define DECLS \
1306 typename T::typeA x;
1307
1308#if defined(FIRST) || defined(SECOND)
1309template <class T>
1310struct Valid1 {
1311 DECLS
1312};
1313#else
1314template <class T>
1315using V1 = Valid1<T>;
1316#endif
1317
1318#if defined(FIRST) || defined(SECOND)
1319template <class T>
1320struct Invalid1 {
1321 DECLS
1322 ACCESS
1323};
1324#else
1325template <class T>
1326using I1 = Invalid1<T>;
1327// expected-error@second.h:* {{'DependentType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1328// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1329#endif
1330#undef DECLS
1331} // namespace DependentType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001332
1333namespace ElaboratedType {
1334#if defined(FIRST)
1335namespace N1 { using type = double; }
1336struct S1 {
1337 N1::type x;
1338};
1339#elif defined(SECOND)
1340namespace N1 { using type = int; }
1341struct S1 {
1342 N1::type x;
1343};
1344#else
1345S1 s1;
1346// expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}}
1347// expected-note@second.h:* {{declaration of 'x' does not match}}
1348#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001349
1350#define DECLS \
1351 NS::type x;
1352
1353#if defined(FIRST) || defined(SECOND)
1354namespace NS { using type = float; }
1355#endif
1356
1357#if defined(FIRST) || defined(SECOND)
1358struct Valid1 {
1359 DECLS
1360};
1361#else
1362Valid1 v1;
1363#endif
1364
1365#if defined(FIRST) || defined(SECOND)
1366struct Invalid1 {
1367 DECLS
1368 ACCESS
1369};
1370#else
1371Invalid1 i1;
1372// expected-error@second.h:* {{'ElaboratedType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1373// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1374#endif
1375#undef DECLS
1376} // namespace ElaboratedType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001377
1378namespace Enum {
1379#if defined(FIRST)
1380enum A1 {};
1381struct S1 {
1382 A1 x;
1383};
1384#elif defined(SECOND)
1385enum A2 {};
1386struct S1 {
1387 A2 x;
1388};
1389#else
1390S1 s1;
1391// expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
1392// expected-note@second.h:* {{declaration of 'x' does not match}}
1393#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001394
1395#define DECLS \
1396 E e = E1;
1397
1398#if defined(FIRST) || defined(SECOND)
1399enum E { E1, E2 };
1400#endif
1401
1402#if defined(FIRST) || defined(SECOND)
1403struct Valid1 {
1404 DECLS
1405};
1406#else
1407Valid1 v1;
1408#endif
1409
1410#if defined(FIRST) || defined(SECOND)
1411struct Invalid1 {
1412 DECLS
1413 ACCESS
1414};
1415#else
1416Invalid1 i1;
1417// expected-error@second.h:* {{'Enum::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1418// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1419#endif
1420#undef DECLS
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001421}
Hans Wennborg22707762017-04-12 16:40:26 +00001422
Richard Trieuce81b192017-05-17 03:23:35 +00001423namespace NestedNamespaceSpecifier {
1424#if defined(FIRST)
1425namespace LevelA1 {
1426using Type = int;
1427}
1428
1429struct S1 {
1430 LevelA1::Type x;
1431};
1432# elif defined(SECOND)
1433namespace LevelB1 {
1434namespace LevelC1 {
1435using Type = int;
1436}
1437}
1438
1439struct S1 {
1440 LevelB1::LevelC1::Type x;
1441};
1442#else
1443S1 s1;
1444// 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')}}
1445// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
1446#endif
1447
1448#if defined(FIRST)
1449namespace LevelA2 { using Type = int; }
1450struct S2 {
1451 LevelA2::Type x;
1452};
1453# elif defined(SECOND)
1454struct S2 {
1455 int x;
1456};
1457#else
1458S2 s2;
1459// 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'}}
1460// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
1461#endif
1462
1463namespace LevelA3 { using Type = int; }
1464namespace LevelB3 { using Type = int; }
1465#if defined(FIRST)
1466struct S3 {
1467 LevelA3::Type x;
1468};
1469# elif defined(SECOND)
1470struct S3 {
1471 LevelB3::Type x;
1472};
1473#else
1474S3 s3;
1475// 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')}}
1476// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
1477#endif
1478
1479#if defined(FIRST)
1480struct TA4 { using Type = int; };
1481struct S4 {
1482 TA4::Type x;
1483};
1484# elif defined(SECOND)
1485struct TB4 { using Type = int; };
1486struct S4 {
1487 TB4::Type x;
1488};
1489#else
1490S4 s4;
1491// 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')}}
1492// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
1493#endif
1494
1495#if defined(FIRST)
1496struct T5 { using Type = int; };
1497struct S5 {
1498 T5::Type x;
1499};
1500# elif defined(SECOND)
1501namespace T5 { using Type = int; };
1502struct S5 {
1503 T5::Type x;
1504};
1505#else
1506S5 s5;
1507// 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')}}
1508// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
1509#endif
1510
1511#if defined(FIRST)
1512namespace N6 {using I = int;}
1513struct S6 {
1514 NestedNamespaceSpecifier::N6::I x;
1515};
1516# elif defined(SECOND)
1517using I = int;
1518struct S6 {
1519 ::NestedNamespaceSpecifier::I x;
1520};
1521#else
1522S6 s6;
1523// 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')}}
1524// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
1525#endif
1526
1527#if defined(FIRST)
1528template <class T, class U>
1529class S7 {
1530 typename T::type *x = {};
1531 int z = x->T::foo();
1532};
1533#elif defined(SECOND)
1534template <class T, class U>
1535class S7 {
1536 typename T::type *x = {};
1537 int z = x->U::foo();
1538};
1539#else
1540template <class T, class U>
1541using U7 = S7<T, U>;
1542// 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}}
1543// expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}}
1544#endif
1545
1546#if defined(FIRST)
1547template <class T>
1548class S8 {
1549 int x = T::template X<int>::value;
1550};
1551#elif defined(SECOND)
1552template <class T>
1553class S8 {
1554 int x = T::template Y<int>::value;
1555};
1556#else
1557template <class T>
1558using U8 = S8<T>;
1559// 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}}
1560// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
1561#endif
1562
1563#if defined(FIRST)
1564namespace N9 { using I = int; }
1565namespace O9 = N9;
1566struct S9 {
1567 O9::I x;
1568};
1569#elif defined(SECOND)
1570namespace N9 { using I = int; }
1571namespace P9 = N9;
1572struct S9 {
1573 P9::I x;
1574};
1575#else
1576S9 s9;
1577// 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')}}
1578// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
1579#endif
Richard Trieu96b41642017-07-01 02:00:05 +00001580
1581namespace N10 {
1582#if defined(FIRST)
1583inline namespace A { struct X {}; }
1584struct S10 {
1585 A::X x;
1586};
1587#elif defined(SECOND)
1588inline namespace B { struct X {}; }
1589struct S10 {
1590 B::X x;
1591};
1592#else
1593S10 s10;
1594// expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
1595// expected-note@first.h:* {{declaration of 'x' does not match}}
1596#endif
1597}
Richard Trieu73cf9242017-11-04 01:20:50 +00001598
1599#define DECLS \
1600 NS1::Type a; \
1601 NS1::NS2::Type b; \
1602 NS1::S c; \
1603 NS3::Type d;
1604
1605#if defined(FIRST) || defined(SECOND)
1606namespace NS1 {
1607 using Type = int;
1608 namespace NS2 {
1609 using Type = double;
1610 }
1611 struct S {};
Richard Trieuce81b192017-05-17 03:23:35 +00001612}
Richard Trieu73cf9242017-11-04 01:20:50 +00001613namespace NS3 = NS1;
1614#endif
1615
1616#if defined(FIRST) || defined(SECOND)
1617struct Valid1 {
1618 DECLS
1619};
1620#else
1621Valid1 v1;
1622#endif
1623
1624#if defined(FIRST) || defined(SECOND)
1625struct Invalid1 {
1626 DECLS
1627 ACCESS
1628};
1629#else
1630Invalid1 i1;
1631// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1632// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1633#endif
1634#undef DECLS
1635
1636#define DECLS \
1637 typename T::type *x = {}; \
1638 int y = x->T::foo(); \
1639 int z = U::template X<int>::value;
1640
1641#if defined(FIRST) || defined(SECOND)
1642template <class T, class U>
1643struct Valid2 {
1644 DECLS
1645};
1646#else
1647template <class T, class U>
1648using V2 = Valid2<T, U>;
1649#endif
1650
1651#if defined(FIRST) || defined(SECOND)
1652template <class T, class U>
1653struct Invalid2 {
1654 DECLS
1655 ACCESS
1656};
1657#else
1658template <class T, class U>
1659using I2 = Invalid2<T, U>;
1660// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1661// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1662#endif
1663#undef DECLS
1664} // namespace NestedNamespaceSpecifier
Richard Trieuce81b192017-05-17 03:23:35 +00001665
Richard Trieu96b49622017-05-31 00:31:58 +00001666namespace TemplateSpecializationType {
1667#if defined(FIRST)
1668template <class T1> struct U1 {};
1669struct S1 {
1670 U1<int> u;
1671};
1672#elif defined(SECOND)
1673template <class T1, class T2> struct U1 {};
1674struct S1 {
1675 U1<int, int> u;
1676};
1677#else
1678S1 s1;
1679// expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}}
1680// expected-note@second.h:* {{declaration of 'u' does not match}}
1681#endif
1682
1683#if defined(FIRST)
1684template <class T1> struct U2 {};
1685struct S2 {
1686 U2<int> u;
1687};
1688#elif defined(SECOND)
1689template <class T1> struct V1 {};
1690struct S2 {
1691 V1<int> u;
1692};
1693#else
1694S2 s2;
1695// expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}}
1696// expected-note@second.h:* {{declaration of 'u' does not match}}
1697#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001698
1699#define DECLS \
1700 OneTemplateArg<int> x; \
1701 OneTemplateArg<double> y; \
1702 OneTemplateArg<char *> z; \
1703 TwoTemplateArgs<int, int> a; \
1704 TwoTemplateArgs<double, float> b; \
1705 TwoTemplateArgs<short *, char> c;
1706
1707#if defined(FIRST) || defined(SECOND)
1708template <class T> struct OneTemplateArg {};
1709template <class T, class U> struct TwoTemplateArgs {};
1710#endif
1711
1712#if defined(FIRST) || defined(SECOND)
1713struct Valid1 {
1714DECLS
1715};
1716#else
1717Valid1 v1;
1718#endif
1719
1720#if defined(FIRST) || defined(SECOND)
1721struct Invalid1 {
1722DECLS
1723ACCESS
1724};
1725#else
1726Invalid1 i1;
1727// expected-error@second.h:* {{'TemplateSpecializationType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1728// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1729#endif
1730#undef DECLS
1731} // namespace TemplateSpecializationType
Richard Trieu96b49622017-05-31 00:31:58 +00001732
Richard Trieu3b261bb72017-06-13 22:21:18 +00001733namespace TemplateArgument {
1734#if defined(FIRST)
1735template <class> struct U1{};
1736struct S1 {
1737 U1<int> x;
1738};
1739#elif defined(SECOND)
1740template <int> struct U1{};
1741struct S1 {
1742 U1<1> x;
1743};
1744#else
1745S1 s1;
1746// expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
1747// expected-note@second.h:* {{declaration of 'x' does not match}}
1748#endif
Richard Trieu1dcb4052017-06-14 01:28:00 +00001749
1750#if defined(FIRST)
1751template <int> struct U2{};
1752struct S2 {
1753 using T = U2<2>;
1754};
1755#elif defined(SECOND)
1756template <int> struct U2{};
1757struct S2 {
1758 using T = U2<(2)>;
1759};
1760#else
1761S2 s2;
1762// 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)>'}}
1763// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}}
1764#endif
1765
1766#if defined(FIRST)
1767template <int> struct U3{};
1768struct S3 {
1769 using T = U3<2>;
1770};
1771#elif defined(SECOND)
1772template <int> struct U3{};
1773struct S3 {
1774 using T = U3<1 + 1>;
1775};
1776#else
1777S3 s3;
1778// 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>'}}
1779// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}}
1780#endif
1781
Richard Trieuee132d62017-06-14 03:17:26 +00001782#if defined(FIRST)
1783template<class> struct T4a {};
1784template <template <class> class T> struct U4 {};
1785struct S4 {
1786 U4<T4a> x;
1787};
1788#elif defined(SECOND)
1789template<class> struct T4b {};
1790template <template <class> class T> struct U4 {};
1791struct S4 {
1792 U4<T4b> x;
1793};
1794#else
1795S4 s4;
1796// expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}}
1797// expected-note@second.h:* {{declaration of 'x' does not match}}
1798#endif
Richard Trieu8844c522017-06-30 22:40:33 +00001799
1800#if defined(FIRST)
1801template <class T> struct U5 {};
1802struct S5 {
1803 U5<int> x;
1804};
1805#elif defined(SECOND)
1806template <class T> struct U5 {};
1807struct S5 {
1808 U5<short> x;
1809};
1810#else
1811S5 s5;
1812// expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}}
1813// expected-note@second.h:* {{declaration of 'x' does not match}}
1814#endif
1815
1816#if defined(FIRST)
1817template <class T> struct U6 {};
1818struct S6 {
1819 U6<int> x;
1820 U6<short> y;
1821};
1822#elif defined(SECOND)
1823template <class T> struct U6 {};
1824struct S6 {
1825 U6<short> y;
1826 U6<int> x;
1827};
1828#else
1829S6 s6;
1830// expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
1831// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
1832#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001833
Richard Trieu7282d322018-04-25 00:31:15 +00001834#if defined(FIRST)
1835struct S7 {
1836 template<int> void run() {}
1837 template<> void run<1>() {}
1838};
1839#elif defined(SECOND)
1840struct S7 {
1841 template<int> void run() {}
1842 void run() {}
1843};
1844#else
1845S7 s7;
1846// expected-error@second.h:* {{'TemplateArgument::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with no template arguments}}
1847// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with template arguments}}
1848#endif
1849
1850#if defined(FIRST)
1851struct S8 {
1852 static int a, b;
1853 template<int&> void run() {}
1854 template<int&, int&> void run() {}
1855 template<> void run<a>() {}
1856};
1857#elif defined(SECOND)
1858struct S8 {
1859 static int a, b;
1860 template<int&> void run() {}
1861 template<int&, int&> void run() {}
1862 template<> void run<a, b>() {}
1863};
1864#else
1865S8 s8;
1866// expected-error@second.h:* {{'TemplateArgument::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 2 template arguments}}
1867// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 1 template argument}}
1868#endif
1869
1870#if defined(FIRST)
1871struct S9 {
1872 static int a, b;
1873 template<int&> void run() {}
1874 template<> void run<a>() {}
1875};
1876#elif defined(SECOND)
1877struct S9 {
1878 static int a, b;
1879 template<int&> void run() {}
1880 template<> void run<b>() {}
1881};
1882#else
1883S9 s9;
1884// expected-error@second.h:* {{'TemplateArgument::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 'b' for 1st template argument}}
1885// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 1st template argument}}
1886#endif
1887
1888#if defined(FIRST)
1889struct S10 {
1890 static int a, b;
1891 template<int, int&...> void run() {}
1892 template<> void run<1, a>() {}
1893};
1894#elif defined(SECOND)
1895struct S10 {
1896 static int a, b;
1897 template<int, int&...> void run() {}
1898 template<> void run<1, b>() {}
1899};
1900#else
1901S10 s10;
1902// expected-error@second.h:* {{'TemplateArgument::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 'b' for 2nd template argument}}
1903// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 2nd template argument}}
1904#endif
1905
1906#if defined(FIRST)
1907struct S11 {
1908 static int a, b;
1909 template<int, int&...> void run() {}
1910 template<> void run<1, a>() {}
1911};
1912#elif defined(SECOND)
1913struct S11 {
1914 static int a, b;
1915 template<int, int&...> void run() {}
1916 template<> void run<1, a, a>() {}
1917};
1918#else
1919S11 s11;
1920// expected-error@second.h:* {{'TemplateArgument::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'run' with 3 template arguments}}
1921// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 2 template arguments}}
1922#endif
1923
Richard Trieu73cf9242017-11-04 01:20:50 +00001924#define DECLS \
1925 OneClass<int> a; \
1926 OneInt<1> b; \
1927 using c = OneClass<float>; \
1928 using d = OneInt<2>; \
1929 using e = OneInt<2 + 2>; \
1930 OneTemplateClass<OneClass> f; \
Richard Trieu7282d322018-04-25 00:31:15 +00001931 OneTemplateInt<OneInt> g; \
1932 static int i1, i2; \
1933 template <int &> \
1934 void Function() {} \
1935 template <int &, int &> \
1936 void Function() {} \
1937 template <> \
1938 void Function<i1>() {} \
1939 template <> \
1940 void Function<i2>() {} \
1941 template <> \
1942 void Function<i1, i2>() {} \
1943 template <> \
1944 void Function<i2, i1>() {}
Richard Trieu73cf9242017-11-04 01:20:50 +00001945
1946#if defined(FIRST) || defined(SECOND)
1947template <class> struct OneClass{};
1948template <int> struct OneInt{};
1949template <template <class> class> struct OneTemplateClass{};
1950template <template <int> class> struct OneTemplateInt{};
1951#endif
1952
1953#if defined(FIRST) || defined(SECOND)
1954struct Valid1 {
1955DECLS
1956};
1957#else
1958Valid1 v1;
1959#endif
1960
1961#if defined(FIRST) || defined(SECOND)
1962struct Invalid1 {
1963DECLS
1964ACCESS
1965};
1966#else
1967Invalid1 i1;
1968// expected-error@second.h:* {{'TemplateArgument::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1969// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1970#endif
1971#undef DECLS
1972} // namespace TemplateArgument
Richard Trieuee132d62017-06-14 03:17:26 +00001973
Richard Trieud9201d02017-06-15 01:35:06 +00001974namespace TemplateTypeParmType {
1975#if defined(FIRST)
1976template <class T1, class T2>
1977struct S1 {
1978 T1 x;
1979};
1980#elif defined(SECOND)
1981template <class T1, class T2>
1982struct S1 {
1983 T2 x;
1984};
1985#else
1986using TemplateTypeParmType::S1;
1987// expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}}
1988// expected-note@second.h:* {{declaration of 'x' does not match}}
1989#endif
1990
1991#if defined(FIRST)
1992template <int ...Ts>
1993struct U2 {};
1994template <int T, int U>
1995class S2 {
1996 typedef U2<U, T> type;
1997 type x;
1998};
1999#elif defined(SECOND)
2000template <int ...Ts>
2001struct U2 {};
2002template <int T, int U>
2003class S2 {
2004 typedef U2<T, U> type;
2005 type x;
2006};
2007#else
2008using TemplateTypeParmType::S2;
2009// expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
2010// expected-note@second.h:* {{declaration of 'x' does not match}}
2011// expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
2012// expected-note@second.h:* {{declaration of 'type' does not match}}
2013#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002014
2015#define DECLS \
2016 T t; \
2017 U u; \
2018 ParameterPack<T> a; \
2019 ParameterPack<T, U> b; \
2020 ParameterPack<U> c; \
2021 ParameterPack<U, T> d;
2022
2023#if defined(FIRST) || defined(SECOND)
2024template <class ...Ts> struct ParameterPack {};
2025#endif
2026
2027#if defined(FIRST) || defined(SECOND)
2028template <class T, class U>
2029struct Valid1 {
2030 DECLS
2031};
2032#else
2033using TemplateTypeParmType::Valid1;
2034#endif
2035
2036#if defined(FIRST) || defined(SECOND)
2037template <class T, class U>
2038struct Invalid1 {
2039 DECLS
2040 ACCESS
2041};
2042#else
2043using TemplateTypeParmType::Invalid1;
2044// expected-error@second.h:* {{'TemplateTypeParmType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2045// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2046#endif
2047#undef DECLS
2048} // namespace TemplateTypeParmType
Richard Trieu3b261bb72017-06-13 22:21:18 +00002049
Richard Trieu6e13ff32017-06-16 02:44:29 +00002050namespace VarDecl {
2051#if defined(FIRST)
2052struct S1 {
2053 static int x;
2054 static int y;
2055};
2056#elif defined(SECOND)
2057struct S1 {
2058 static int y;
2059 static int x;
2060};
2061#else
2062S1 s1;
2063// 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'}}
2064// expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}}
2065#endif
2066
2067#if defined(FIRST)
2068struct S2 {
2069 static int x;
2070};
2071#elif defined(SECOND)
2072using I = int;
2073struct S2 {
2074 static I x;
2075};
2076#else
2077S2 s2;
2078// 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')}}
2079// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}}
2080#endif
2081
2082#if defined(FIRST)
2083struct S3 {
2084 static const int x = 1;
2085};
2086#elif defined(SECOND)
2087struct S3 {
2088 static const int x;
2089};
2090#else
2091S3 s3;
2092// 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}}
2093// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}}
2094#endif
2095
2096#if defined(FIRST)
2097struct S4 {
2098 static const int x = 1;
2099};
2100#elif defined(SECOND)
2101struct S4 {
2102 static const int x = 2;
2103};
2104#else
2105S4 s4;
2106// 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}}
2107// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}}
2108#endif
2109
2110#if defined(FIRST)
2111struct S5 {
2112 static const int x = 1;
2113};
2114#elif defined(SECOND)
2115struct S5 {
2116 static constexpr int x = 1;
2117};
2118#else
2119S5 s5;
2120// 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}}
2121// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}}
2122#endif
2123
2124#if defined(FIRST)
2125struct S6 {
2126 static const int x = 1;
2127};
2128#elif defined(SECOND)
2129struct S6 {
2130 static const int y = 1;
2131};
2132#else
2133S6 s6;
2134// expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}}
2135// expected-note@second.h:* {{definition has no member 'x'}}
2136#endif
2137
2138#if defined(FIRST)
2139struct S7 {
2140 static const int x = 1;
2141};
2142#elif defined(SECOND)
2143struct S7 {
2144 static const unsigned x = 1;
2145};
2146#else
2147S7 s7;
2148// expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}}
2149// expected-note@second.h:* {{declaration of 'x' does not match}}
2150#endif
2151
2152#if defined(FIRST)
2153struct S8 {
2154public:
2155 static const int x = 1;
2156};
2157#elif defined(SECOND)
2158struct S8 {
2159 static const int x = 1;
2160public:
2161};
2162#else
2163S8 s8;
2164// expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}}
2165// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2166#endif
2167
2168#if defined(FIRST)
2169struct S9 {
2170 static const int x = 1;
2171};
2172#elif defined(SECOND)
2173struct S9 {
2174 static int x;
2175};
2176#else
2177S9 s9;
2178// expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}}
2179// expected-note@second.h:* {{declaration of 'x' does not match}}
2180#endif
2181
Richard Trieu73cf9242017-11-04 01:20:50 +00002182#define DECLS \
2183 static int a; \
2184 static I b; \
2185 static const int c = 1; \
2186 static constexpr int d = 5;
2187
2188#if defined(FIRST) || defined(SECOND)
2189using I = int;
Richard Trieu6e13ff32017-06-16 02:44:29 +00002190#endif
2191
Richard Trieu73cf9242017-11-04 01:20:50 +00002192#if defined(FIRST) || defined(SECOND)
2193struct Valid1 {
2194 DECLS
Richard Trieu6e13ff32017-06-16 02:44:29 +00002195};
Richard Trieu6e13ff32017-06-16 02:44:29 +00002196#else
Richard Trieu73cf9242017-11-04 01:20:50 +00002197Valid1 v1;
Richard Trieu6e13ff32017-06-16 02:44:29 +00002198#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002199
2200#if defined(FIRST) || defined(SECOND)
2201struct Invalid1 {
2202 DECLS
2203 ACCESS
2204};
2205#else
2206Invalid1 i1;
2207// expected-error@second.h:* {{'VarDecl::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2208// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2209#endif
2210#undef DECLS
2211} // namespace VarDecl
Richard Trieu6e13ff32017-06-16 02:44:29 +00002212
Richard Trieuac6a1b62017-07-08 02:04:42 +00002213namespace Friend {
2214#if defined(FIRST)
2215struct T1 {};
2216struct S1 {
2217 friend class T1;
2218};
2219#elif defined(SECOND)
2220struct T1 {};
2221struct S1 {
2222 friend T1;
2223};
2224#else
2225S1 s1;
2226// expected-error@second.h:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T1'}}
2227// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T1'}}
2228#endif
2229
2230#if defined(FIRST)
2231struct T2 {};
2232struct S2 {
2233 friend class T2;
2234};
2235#elif defined(SECOND)
2236struct T2 {};
2237struct S2 {
2238 friend struct T2;
2239};
2240#else
2241S2 s2;
2242// expected-error@second.h:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}}
2243// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T2'}}
2244#endif
2245
2246#if defined(FIRST)
Richard Trieuac6a1b62017-07-08 02:04:42 +00002247struct T4 {};
2248struct S4 {
2249 friend T4;
2250};
2251#elif defined(SECOND)
2252struct S4 {
2253 friend void T4();
2254};
2255#else
2256S4 s4;
2257// expected-error@second.h:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}}
2258// expected-note@first.h:* {{but in 'FirstModule' found friend class}}
2259#endif
2260
2261#if defined(FIRST)
2262struct S5 {
2263 friend void T5a();
2264};
2265#elif defined(SECOND)
2266struct S5 {
2267 friend void T5b();
2268};
2269#else
2270S5 s5;
2271// expected-error@second.h:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}}
2272// expected-note@first.h:* {{but in 'FirstModule' found friend function 'T5a'}}
2273#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002274
2275#define DECLS \
2276 friend class FriendA; \
2277 friend struct FriendB; \
2278 friend FriendC; \
Richard Trieu73cf9242017-11-04 01:20:50 +00002279 friend void Function();
2280
2281#if defined(FIRST) || defined(SECOND)
2282class FriendA {};
2283class FriendB {};
2284class FriendC {};
Richard Trieu73cf9242017-11-04 01:20:50 +00002285#endif
2286
2287#if defined(FIRST) || defined(SECOND)
2288struct Valid1 {
2289 DECLS
2290};
2291#else
2292Valid1 v1;
2293#endif
2294
2295#if defined(FIRST) || defined(SECOND)
2296struct Invalid1 {
2297 DECLS
2298 ACCESS
2299};
2300#else
2301Invalid1 i1;
2302// expected-error@second.h:* {{'Friend::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2303// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2304#endif
2305#undef DECLS
2306} // namespace Friend
Richard Trieu498117b2017-08-23 02:43:59 +00002307
2308namespace TemplateParameters {
2309#if defined(FIRST)
2310template <class A>
2311struct S1 {};
2312#elif defined(SECOND)
2313template <class B>
2314struct S1 {};
2315#else
2316using TemplateParameters::S1;
2317// expected-error@second.h:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}}
2318// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2319#endif
2320
2321#if defined(FIRST)
2322template <class A = double>
2323struct S2 {};
2324#elif defined(SECOND)
2325template <class A = int>
2326struct S2 {};
2327#else
2328using TemplateParameters::S2;
2329// 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}}
2330// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2331#endif
2332
2333#if defined(FIRST)
2334template <class A = int>
2335struct S3 {};
2336#elif defined(SECOND)
2337template <class A>
2338struct S3 {};
2339#else
2340using TemplateParameters::S3;
2341// 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}}
2342// expected-note@first.h:* {{but in 'FirstModule' found template parameter with default argument}}
2343#endif
2344
2345#if defined(FIRST)
2346template <int A>
2347struct S4 {};
2348#elif defined(SECOND)
2349template <int A = 2>
2350struct S4 {};
2351#else
2352using TemplateParameters::S4;
2353// 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}}
2354// expected-note@first.h:* {{but in 'FirstModule' found template parameter with no default argument}}
2355#endif
2356
2357#if defined(FIRST)
2358template <int> class S5_first {};
2359template <template<int> class A = S5_first>
2360struct S5 {};
2361#elif defined(SECOND)
2362template <int> class S5_second {};
2363template <template<int> class A = S5_second>
2364struct S5 {};
2365#else
2366using TemplateParameters::S5;
2367// 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}}
2368// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2369#endif
2370
2371#if defined(FIRST)
2372template <class A>
2373struct S6 {};
2374#elif defined(SECOND)
2375template <class>
2376struct S6 {};
2377#else
2378using TemplateParameters::S6;
2379// expected-error@second.h:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}}
2380// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2381#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002382
2383#define DECLS
2384
2385#if defined(FIRST) || defined(SECOND)
2386template <class> class DefaultArg;
2387#endif
2388
2389#if defined(FIRST) || defined(SECOND)
2390template <int, class, template <class> class,
2391 int A, class B, template <int> class C,
2392 int D = 1, class E = int, template <class F> class = DefaultArg>
2393struct Valid1 {
2394 DECLS
2395};
2396#else
2397using TemplateParameters::Valid1;
2398#endif
2399
2400#if defined(FIRST) || defined(SECOND)
2401template <int, class, template <class> class,
2402 int A, class B, template <int> class C,
2403 int D = 1, class E = int, template <class F> class = DefaultArg>
2404struct Invalid1 {
2405 DECLS
2406 ACCESS
2407};
2408#else
2409using TemplateParameters::Invalid1;
2410// expected-error@second.h:* {{'TemplateParameters::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2411// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2412#endif
2413#undef DECLS
Richard Trieu498117b2017-08-23 02:43:59 +00002414} // namespace TemplateParameters
2415
Richard Trieue13eabe2017-09-30 02:19:17 +00002416namespace BaseClass {
2417#if defined(FIRST)
2418struct B1 {};
2419struct S1 : B1 {};
2420#elif defined(SECOND)
2421struct S1 {};
2422#else
2423S1 s1;
2424// expected-error@second.h:* {{'BaseClass::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 base classes}}
2425// expected-note@first.h:* {{but in 'FirstModule' found 1 base class}}
2426#endif
2427
2428#if defined(FIRST)
2429struct S2 {};
2430#elif defined(SECOND)
2431struct B2 {};
2432struct S2 : virtual B2 {};
2433#else
2434S2 s2;
2435// expected-error@second.h:* {{'BaseClass::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 base class}}
2436// expected-note@first.h:* {{but in 'FirstModule' found 0 base classes}}
2437#endif
2438
2439#if defined(FIRST)
2440struct B3a {};
2441struct S3 : B3a {};
2442#elif defined(SECOND)
2443struct B3b {};
2444struct S3 : virtual B3b {};
2445#else
2446S3 s3;
2447// expected-error@second.h:* {{'BaseClass::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2448// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2449#endif
2450
2451#if defined(FIRST)
2452struct B4a {};
2453struct S4 : B4a {};
2454#elif defined(SECOND)
2455struct B4b {};
2456struct S4 : B4b {};
2457#else
2458S4 s4;
2459// 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'}}
2460// expected-note@first.h:* {{but in 'FirstModule' found 1st base class with different type 'BaseClass::B4a'}}
2461#endif
2462
2463#if defined(FIRST)
2464struct B5a {};
2465struct S5 : virtual B5a {};
2466#elif defined(SECOND)
2467struct B5a {};
2468struct S5 : B5a {};
2469#else
2470S5 s5;
2471// expected-error@second.h:* {{'BaseClass::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 virtual base classes}}
2472// expected-note@first.h:* {{but in 'FirstModule' found 1 virtual base class}}
2473#endif
2474
2475#if defined(FIRST)
2476struct B6a {};
2477struct S6 : B6a {};
2478#elif defined(SECOND)
2479struct B6a {};
2480struct S6 : virtual B6a {};
2481#else
2482S6 s6;
2483// expected-error@second.h:* {{'BaseClass::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2484// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2485#endif
2486
2487#if defined(FIRST)
2488struct B7a {};
2489struct S7 : protected B7a {};
2490#elif defined(SECOND)
2491struct B7a {};
2492struct S7 : B7a {};
2493#else
2494S7 s7;
2495// 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}}
2496// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B7a' with protected access specifier}}
2497#endif
2498
2499#if defined(FIRST)
2500struct B8a {};
2501struct S8 : public B8a {};
2502#elif defined(SECOND)
2503struct B8a {};
2504struct S8 : private B8a {};
2505#else
2506S8 s8;
2507// 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}}
2508// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B8a' with public access specifier}}
2509#endif
2510
2511#if defined(FIRST)
2512struct B9a {};
2513struct S9 : private B9a {};
2514#elif defined(SECOND)
2515struct B9a {};
2516struct S9 : public B9a {};
2517#else
2518S9 s9;
2519// 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}}
2520// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B9a' with private access specifier}}
2521#endif
2522
2523#if defined(FIRST)
2524struct B10a {};
2525struct S10 : B10a {};
2526#elif defined(SECOND)
2527struct B10a {};
2528struct S10 : protected B10a {};
2529#else
2530S10 s10;
2531// 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}}
2532// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B10a' with no access specifier}}
2533#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002534
2535#define DECLS
2536
2537#if defined(FIRST) || defined(SECOND)
2538struct Base1 {};
2539struct Base2 {};
2540struct Base3 {};
2541struct Base4 {};
2542struct Base5 {};
2543#endif
2544
2545#if defined(FIRST) || defined(SECOND)
2546struct Valid1 :
2547 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2548
2549 DECLS
2550};
2551#else
2552Valid1 v1;
2553#endif
2554
2555#if defined(FIRST) || defined(SECOND)
2556struct Invalid1 :
2557 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2558
2559 DECLS
2560 ACCESS
2561};
2562#else
2563Invalid1 i1;
2564// expected-error@second.h:* {{'BaseClass::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2565// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2566#endif
2567#undef DECLS
Richard Trieue13eabe2017-09-30 02:19:17 +00002568} // namespace BaseClass
2569
Richard Trieu15970af2018-04-13 22:34:43 +00002570namespace PointersAndReferences {
2571#if defined(FIRST) || defined(SECOND)
2572template<typename> struct Wrapper{};
2573#endif
2574
2575#if defined(FIRST)
2576struct S1 {
2577 Wrapper<int*> x;
2578};
2579#elif defined(SECOND)
2580struct S1 {
2581 Wrapper<float*> x;
2582};
2583#else
2584S1 s1;
2585// expected-error@first.h:* {{PointersAndReferences::S1::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S1' in module 'SecondModule'}}
2586// expected-note@second.h:* {{declaration of 'x' does not match}}
2587#endif
2588
2589#if defined(FIRST)
2590struct S2 {
2591 Wrapper<int &&> x;
2592};
2593#elif defined(SECOND)
2594struct S2 {
2595 Wrapper<float &&> x;
2596};
2597#else
2598S2 s2;
2599// expected-error@first.h:* {{PointersAndReferences::S2::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S2' in module 'SecondModule'}}
2600// expected-note@second.h:* {{declaration of 'x' does not match}}
2601#endif
2602
2603#if defined(FIRST)
2604struct S3 {
2605 Wrapper<int *> x;
2606};
2607#elif defined(SECOND)
2608struct S3 {
2609 Wrapper<float *> x;
2610};
2611#else
2612S3 s3;
2613// expected-error@first.h:* {{PointersAndReferences::S3::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S3' in module 'SecondModule'}}
2614// expected-note@second.h:* {{declaration of 'x' does not match}}
2615#endif
2616
2617#if defined(FIRST)
2618struct S4 {
2619 Wrapper<int &> x;
2620};
2621#elif defined(SECOND)
2622struct S4 {
2623 Wrapper<float &> x;
2624};
2625#else
2626S4 s4;
2627// expected-error@first.h:* {{PointersAndReferences::S4::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S4' in module 'SecondModule'}}
2628// expected-note@second.h:* {{declaration of 'x' does not match}}
2629#endif
2630
2631#if defined(FIRST)
2632struct S5 {
2633 Wrapper<S5 *> x;
2634};
2635#elif defined(SECOND)
2636struct S5 {
2637 Wrapper<const S5 *> x;
2638};
2639#else
2640S5 s5;
2641// expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 'SecondModule' is not present in definition of 'PointersAndReferences::S5' in module 'FirstModule'}}
2642// expected-note@first.h:* {{declaration of 'x' does not match}}
2643#endif
2644
2645#if defined(FIRST)
2646struct S6 {
2647 Wrapper<int &> x;
2648};
2649#elif defined(SECOND)
2650struct S6 {
2651 Wrapper<const int &> x;
2652};
2653#else
2654S6 s6;
2655// expected-error@first.h:* {{PointersAndReferences::S6::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S6' in module 'SecondModule'}}
2656// expected-note@second.h:* {{declaration of 'x' does not match}}
2657#endif
2658
2659#define DECLS \
2660 Wrapper<int *> x1; \
2661 Wrapper<float *> x2; \
2662 Wrapper<const float *> x3; \
2663 Wrapper<int &> x4; \
2664 Wrapper<int &&> x5; \
2665 Wrapper<const int &> x6; \
2666 Wrapper<S1 *> x7; \
2667 Wrapper<S1 &> x8; \
2668 Wrapper<S1 &&> x9;
2669
2670#if defined(FIRST) || defined(SECOND)
2671struct Valid1 {
2672 DECLS
2673};
2674#else
2675Valid1 v1;
2676#endif
2677
2678#if defined(FIRST) || defined(SECOND)
2679struct Invalid1 {
2680 DECLS
2681 ACCESS
2682};
2683#else
2684Invalid1 i1;
2685// expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2686// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2687#endif
2688#undef DECLS
2689} // namespace PointersAndReferences
2690
Richard Trieu9359e8f2018-05-30 01:12:26 +00002691namespace FunctionTemplate {
2692#if defined(FIRST)
2693struct S1 {
2694 template <int, int> void foo();
2695};
2696#elif defined(SECOND)
2697struct S1 {
2698 template <int> void foo();
2699};
2700#else
2701S1 s1;
2702// expected-error@first.h:* {{'FunctionTemplate::S1::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S1' in module 'SecondModule'}}
2703// expected-note@second.h:* {{declaration of 'foo' does not match}}
2704#endif
2705
2706#if defined(FIRST)
2707struct S2 {
2708 template <char> void foo();
2709};
2710#elif defined(SECOND)
2711struct S2 {
2712 template <int> void foo();
2713};
2714#else
2715S2 s2;
2716// expected-error@first.h:* {{'FunctionTemplate::S2::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S2' in module 'SecondModule'}}
2717// expected-note@second.h:* {{declaration of 'foo' does not match}}
2718#endif
2719
2720#if defined(FIRST)
2721struct S3 {
2722 template <int x> void foo();
2723};
2724#elif defined(SECOND)
2725struct S3 {
2726 template <int y> void foo();
2727};
2728#else
2729S3 s3;
2730// expected-error@second.h:* {{'FunctionTemplate::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter named 'y'}}
2731// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2732#endif
2733
2734#if defined(FIRST)
2735struct S4 {
2736 template <int x> void foo();
2737};
2738#elif defined(SECOND)
2739struct S4 {
2740 template <int x> void bar();
2741};
2742#else
2743S4 s4;
2744// expected-error@first.h:* {{'FunctionTemplate::S4::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S4' in module 'SecondModule'}}
2745// expected-note@second.h:* {{definition has no member 'foo'}}
2746#endif
2747
2748#if defined(FIRST)
2749struct S5 {
2750 template <int x> void foo();
2751};
2752#elif defined(SECOND)
2753struct S5 {
2754 public:
2755 template <int x> void foo();
2756};
2757#else
2758S5 s5;
2759// expected-error@second.h:* {{'FunctionTemplate::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2760// expected-note@first.h:* {{but in 'FirstModule' found function template}}
2761#endif
2762
2763#if defined(FIRST)
2764struct S6 {
2765 template <typename x = int> void foo();
2766};
2767#elif defined(SECOND)
2768struct S6 {
2769 template <typename x> void foo();
2770};
2771#else
2772S6 s6;
2773// expected-error@second.h:* {{'FunctionTemplate::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no default argument}}
2774// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2775#endif
2776
2777#if defined(FIRST)
2778struct S7 {
2779 template <typename x = void> void foo();
2780};
2781#elif defined(SECOND)
2782struct S7 {
2783 template <typename x = int> void foo();
2784};
2785#else
2786S7 s7;
2787// expected-error@second.h:* {{'FunctionTemplate::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 'int'}}
2788// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'void'}}
2789#endif
2790
2791#if defined(FIRST)
2792template <int>
2793struct U8 {};
2794struct S8 {
2795 template <template<int> class x = U8> void foo();
2796};
2797#elif defined(SECOND)
2798template <int>
2799struct T8 {};
2800struct S8{
2801 template <template<int> class x = T8> void foo();
2802};
2803#else
2804S8 s8;
2805// expected-error@second.h:* {{'FunctionTemplate::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 'T8'}}
2806// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'U8'}}
2807#endif
2808
2809#if defined(FIRST)
2810template <int>
2811struct U9 {};
2812struct S9 { S9();
2813 template <template<int> class x = U9> void foo();
2814};
2815#elif defined(SECOND)
2816struct S9 { S9();
2817 template <template<int> class x> void foo();
2818};
2819#else
2820S9 s9;
2821// expected-error@second.h:* {{'FunctionTemplate::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no default argument}}
2822// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2823#endif
2824
2825#if defined(FIRST)
2826struct S10 {
2827 template <template<int> class x> void foo();
2828 template <template<typename> class x> void foo();
2829};
2830#elif defined(SECOND)
2831struct S10 {
2832 template <template<typename> class x> void foo();
2833 template <template<int> class x> void foo();
2834};
2835#else
2836S10 s10;
2837// expected-error@second.h:* {{'FunctionTemplate::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with one type}}
2838// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
2839#endif
2840
2841#if defined(FIRST)
2842struct S11 {
2843 template <template<int> class x> void foo();
2844};
2845#elif defined(SECOND)
2846struct S11 {
2847 template <template<int> class> void foo();
2848};
2849#else
2850S11 s11;
2851// expected-error@second.h:* {{'FunctionTemplate::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no name}}
2852// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2853#endif
2854
2855#if defined(FIRST)
2856struct S12 {
2857 template <class> void foo();
2858 template <class, class> void foo();
2859};
2860#elif defined(SECOND)
2861struct S12 {
2862 template <class, class> void foo();
2863 template <class> void foo();
2864};
2865#else
2866S12 s12;
2867// expected-error@second.h:* {{'FunctionTemplate::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 2 template parameters}}
2868// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1 template parameter}}
2869#endif
2870
2871#if defined(FIRST)
2872struct S13 {
2873 template <class = int> void foo();
2874};
2875#elif defined(SECOND)
2876struct S13 {
2877 template <class = void> void foo();
2878};
2879#else
2880S13 s13;
2881// expected-error@second.h:* {{'FunctionTemplate::S13' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 'void'}}
2882// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'int'}}
2883#endif
2884
2885#if defined(FIRST)
2886struct S14 {
2887 template <class = void> void foo();
2888};
2889#elif defined(SECOND)
2890struct S14 {
2891 template <class> void foo();
2892};
2893#else
2894S14 s14;
2895// expected-error@second.h:* {{'FunctionTemplate::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with no default argument}}
2896// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2897#endif
2898
2899#if defined(FIRST)
2900struct S15 {
2901 template <class> void foo();
2902};
2903#elif defined(SECOND)
2904struct S15 {
2905 template <class = void> void foo();
2906};
2907#else
2908S15 s15;
2909// expected-error@second.h:* {{'FunctionTemplate::S15' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument}}
2910// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
2911#endif
2912
2913#if defined(FIRST)
2914struct S16 {
2915 template <short> void foo();
2916};
2917#elif defined(SECOND)
2918struct S16 {
2919 template <short = 1> void foo();
2920};
2921#else
2922S16 s16;
2923// expected-error@second.h:* {{'FunctionTemplate::S16' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument}}
2924// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
2925#endif
2926
2927#if defined(FIRST)
2928struct S17 {
2929 template <short = 2> void foo();
2930};
2931#elif defined(SECOND)
2932struct S17 {
2933 template <short = 1 + 1> void foo();
2934};
2935#else
2936S17 s17;
2937// expected-error@second.h:* {{'FunctionTemplate::S17' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with default argument 1 + 1}}
2938// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 2}}
2939#endif
2940
2941#if defined(FIRST)
2942struct S18 {
2943 template <short> void foo();
2944 template <int> void foo();
2945};
2946#elif defined(SECOND)
2947struct S18 {
2948 template <int> void foo();
2949 template <short> void foo();
2950};
2951#else
2952S18 s18;
2953// expected-error@second.h:* {{'FunctionTemplate::S18' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter with one type}}
2954// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
2955#endif
2956
2957#if defined(FIRST)
2958struct S19 {
2959 template <short> void foo();
2960 template <short...> void foo();
2961};
2962#elif defined(SECOND)
2963struct S19 {
2964 template <short...> void foo();
2965 template <short> void foo();
2966};
2967#else
2968S19 s19;
2969// expected-error@second.h:* {{'FunctionTemplate::S19' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a template parameter pack}}
2970// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
2971#endif
2972
2973#if defined(FIRST)
2974struct S20 {
2975 template <class> void foo();
2976 template <class...> void foo();
2977};
2978#elif defined(SECOND)
2979struct S20 {
2980 template <class...> void foo();
2981 template <class> void foo();
2982};
2983#else
2984S20 s20;
2985// expected-error@second.h:* {{'FunctionTemplate::S20' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a template parameter pack}}
2986// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
2987#endif
2988
2989#if defined(FIRST)
2990struct S21 {
2991 template <template<class> class...> void foo();
2992 template <template<class> class> void foo();
2993};
2994#elif defined(SECOND)
2995struct S21 {
2996 template <template<class> class> void foo();
2997 template <template<class> class...> void foo();
2998};
2999#else
3000S21 s21;
3001// expected-error@second.h:* {{'FunctionTemplate::S21' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
3002// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter being a template parameter pack}}
3003#endif
3004
3005#if defined(FIRST)
3006struct S22 {
3007 template <template<class> class> void foo();
3008 template <class> void foo();
3009 template <int> void foo();
3010};
3011#elif defined(SECOND)
3012struct S22 {
3013 template <class> void foo();
3014 template <int> void foo();
3015 template <template<class> class> void foo();
3016};
3017#else
3018S22 s22;
3019// expected-error@second.h:* {{'FunctionTemplate::S22' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a type template parameter}}
3020// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a template template parameter}}
3021#endif
3022
3023#if defined(FIRST)
3024struct S23 {
3025 template <class> void foo();
3026 template <int> void foo();
3027 template <template<class> class> void foo();
3028};
3029#elif defined(SECOND)
3030struct S23 {
3031 template <int> void foo();
3032 template <template<class> class> void foo();
3033 template <class> void foo();
3034};
3035#else
3036S23 s23;
3037// expected-error@second.h:* {{'FunctionTemplate::S23' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a non-type template parameter}}
3038// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a type template parameter}}
3039#endif
3040
3041#if defined(FIRST)
3042struct S24 {
3043 template <int> void foo();
3044 template <template<class> class> void foo();
3045 template <class> void foo();
3046};
3047#elif defined(SECOND)
3048struct S24 {
3049 template <template<class> class> void foo();
3050 template <class> void foo();
3051 template <int> void foo();
3052};
3053#else
3054S24 s24;
3055// expected-error@second.h:* {{'FunctionTemplate::S24' has different definitions in different modules; first difference is definition in module 'SecondModule' found function template 'foo' with 1st template parameter being a template template parameter}}
3056// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a non-type template parameter}}
3057#endif
3058
3059#if defined(FIRST)
3060struct S25 {
3061 template <int> void foo();
3062};
3063#elif defined(SECOND)
3064struct S25 {
3065 public:
3066 template <int> void foo();
3067};
3068#else
3069S25 s25;
3070// expected-error@second.h:* {{'FunctionTemplate::S25' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3071// expected-note@first.h:* {{but in 'FirstModule' found function template}}
3072#endif
3073
3074#define DECLS \
3075 template <int> \
3076 void nontype1(); \
3077 template <int x> \
3078 void nontype2(); \
3079 template <int, int> \
3080 void nontype3(); \
3081 template <int x = 5> \
3082 void nontype4(); \
3083 template <int... x> \
3084 void nontype5(); \
3085 \
3086 template <class> \
3087 void type1(); \
3088 template <class x> \
3089 void type2(); \
3090 template <class, class> \
3091 void type3(); \
3092 template <class x = int> \
3093 void type4(); \
3094 template <class... x> \
3095 void type5(); \
3096 \
3097 template <template <int> class> \
3098 void template1(); \
3099 template <template <int> class x> \
3100 void template2(); \
3101 template <template <int> class, template <int> class> \
3102 void template3(); \
3103 template <template <int> class x = U> \
3104 void template4(); \
3105 template <template <int> class... x> \
3106 void template5();
3107
3108#if defined(FIRST) || defined(SECOND)
3109template<int>
3110struct U {};
3111struct Valid1 {
3112 DECLS
3113};
3114#else
3115Valid1 v1;
3116#endif
3117
3118#if defined(FIRST) || defined(SECOND)
3119struct Invalid1 {
3120 DECLS
3121 ACCESS
3122};
3123#else
3124Invalid1 i1;
3125// expected-error@second.h:* {{'FunctionTemplate::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3126// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3127#endif
3128#undef DECLS
3129}
Richard Trieu73cf9242017-11-04 01:20:50 +00003130
Richard Trieuab4d7302018-07-25 22:52:05 +00003131namespace Enums {
3132#if defined(FIRST)
3133enum E1 { x11 };
3134#elif defined(SECOND)
3135enum E1 {};
3136#else
3137E1 e1;
3138// expected-error@first.h:* {{'Enums::x11' from module 'FirstModule' is not present in definition of 'Enums::E1' in module 'SecondModule'}}
3139// expected-note@second.h:* {{definition has no member 'x11'}}
3140#endif
3141
3142#if defined(FIRST)
3143enum E2 {};
3144#elif defined(SECOND)
3145enum E2 { x21 };
3146#else
3147E2 e2;
3148// expected-error@second.h:* {{'Enums::E2' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 1 element}}
3149// expected-note@first.h:* {{but in 'FirstModule' found enum with 0 elements}}
3150#endif
3151
3152#if defined(FIRST)
3153enum E3 { x31 };
3154#elif defined(SECOND)
3155enum E3 { x32 };
3156#else
3157E3 e3;
3158// expected-error@first.h:* {{'Enums::x31' from module 'FirstModule' is not present in definition of 'Enums::E3' in module 'SecondModule'}}
3159// expected-note@second.h:* {{definition has no member 'x31'}}
3160#endif
3161
3162#if defined(FIRST)
3163enum E4 { x41 };
3164#elif defined(SECOND)
3165enum E4 { x41, x42 };
3166#else
3167E4 e4;
3168// expected-error@second.h:* {{'Enums::E4' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 2 elements}}
3169// expected-note@first.h:* {{but in 'FirstModule' found enum with 1 element}}
3170#endif
3171
3172#if defined(FIRST)
3173enum E5 { x51, x52 };
3174#elif defined(SECOND)
3175enum E5 { x51 };
3176#else
3177E5 e5;
3178// expected-error@first.h:* {{'Enums::x52' from module 'FirstModule' is not present in definition of 'Enums::E5' in module 'SecondModule'}}
3179// expected-note@second.h:* {{definition has no member 'x52'}}
3180#endif
3181
3182#if defined(FIRST)
3183enum E6 { x61, x62 };
3184#elif defined(SECOND)
3185enum E6 { x62, x61 };
3186#else
3187E6 e6;
3188// expected-error@second.h:* {{'Enums::E6' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element has name 'x62'}}
3189// expected-note@first.h:* {{but in 'FirstModule' found 1st element has name 'x61'}}
3190#endif
3191
3192#if defined(FIRST)
3193enum E7 { x71 = 0 };
3194#elif defined(SECOND)
3195enum E7 { x71 };
3196#else
3197E7 e7;
3198// expected-error@second.h:* {{'Enums::E7' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x71' has an initilizer}}
3199// expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x71' does not have an initializer}}
3200#endif
3201
3202#if defined(FIRST)
3203enum E8 { x81 };
3204#elif defined(SECOND)
3205enum E8 { x81 = 0 };
3206#else
3207E8 e8;
3208// expected-error@second.h:* {{'Enums::E8' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x81' does not have an initilizer}}
3209// expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x81' has an initializer}}
3210#endif
3211
3212#if defined(FIRST)
3213enum E9 { x91 = 0, x92 = 1 };
3214#elif defined(SECOND)
3215enum E9 { x91 = 0, x92 = 2 - 1 };
3216#else
3217E9 e9;
3218// expected-error@second.h:* {{'Enums::E9' has different definitions in different modules; definition in module 'SecondModule' first difference is 2nd element 'x92' has an initializer}}
3219// expected-note@first.h:* {{but in 'FirstModule' found 2nd element 'x92' has different initializer}}
3220#endif
3221
3222#if defined(FIRST)
3223enum class E10 : int {};
3224#elif defined(SECOND)
3225enum class E10 {};
3226#else
3227E10 e10;
3228// expected-error@second.h:* {{'Enums::E10' has different definitions in different modules; definition in module 'SecondModule' first difference is enum without specified type}}
3229// expected-note@first.h:* {{but in 'FirstModule' found enum with specified type}}
3230#endif
3231
3232#if defined(FIRST)
3233enum E11 {};
3234#elif defined(SECOND)
3235enum E11 : int {};
3236#else
3237E11 e11;
3238// expected-error@second.h:* {{'Enums::E11' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type}}
3239// expected-note@first.h:* {{but in 'FirstModule' found enum without specified type}}
3240#endif
3241
3242#if defined(FIRST)
3243enum struct E12 : long {};
3244#elif defined(SECOND)
3245enum struct E12 : int {};
3246#else
3247E12 e12;
3248// expected-error@second.h:* {{'Enums::E12' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type 'int'}}
3249// expected-note@first.h:* {{but in 'FirstModule' found enum with specified type 'long'}}
3250#endif
3251
3252#if defined(FIRST)
3253enum struct E13 {};
3254#elif defined(SECOND)
3255enum E13 {};
3256#else
3257E13 e13;
3258// expected-error@second.h:* {{'Enums::E13' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is not scoped}}
3259// expected-note@first.h:* {{but in 'FirstModule' found enum that is scoped}}
3260#endif
3261
3262#if defined(FIRST)
3263enum E14 {};
3264#elif defined(SECOND)
3265enum struct E14 {};
3266#else
3267E14 e14;
3268// expected-error@second.h:* {{'Enums::E14' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is scoped}}
3269// expected-note@first.h:* {{but in 'FirstModule' found enum that is not scoped}}
3270#endif
3271
3272#if defined(FIRST)
3273enum class E15 {};
3274#elif defined(SECOND)
3275enum struct E15 {};
3276#else
3277E15 e15;
3278// expected-error@second.h:* {{'Enums::E15' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword struct}}
3279// expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword class}}
3280#endif
3281
3282#if defined(FIRST)
3283enum struct E16 {};
3284#elif defined(SECOND)
3285enum class E16 {};
3286#else
3287E16 e16;
3288// expected-error@second.h:* {{'Enums::E16' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword class}}
3289// expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword struct}}
3290#endif
3291
3292#if defined(FIRST)
3293enum Valid { v1 = (struct S*)0 == (struct S*)0 };
3294#elif defined(SECOND)
3295struct S {};
3296enum Valid { v1 = (struct S*)0 == (struct S*)0 };
3297#else
3298Valid V;
3299#endif
3300} // namespace Enums
3301
Richard Trieu73cf9242017-11-04 01:20:50 +00003302// Collection of interesting cases below.
3303
3304// Naive parsing of AST can lead to cycles in processing. Ensure
3305// self-references don't trigger an endless cycles of AST node processing.
3306namespace SelfReference {
3307#if defined(FIRST)
3308template <template <int> class T> class Wrapper {};
3309
3310template <int N> class S {
3311 S(Wrapper<::SelfReference::S> &Ref) {}
3312};
3313
3314struct Xx {
3315 struct Yy {
Richard Trieufe564052017-04-20 02:53:53 +00003316 };
Richard Trieu73cf9242017-11-04 01:20:50 +00003317};
Richard Trieufe564052017-04-20 02:53:53 +00003318
Richard Trieu73cf9242017-11-04 01:20:50 +00003319Xx::Xx::Xx::Yy yy;
Richard Trieue7f7ed22017-02-22 01:11:25 +00003320
Richard Trieu73cf9242017-11-04 01:20:50 +00003321namespace NNS {
3322template <typename> struct Foo;
3323template <template <class> class T = NNS::Foo>
3324struct NestedNamespaceSpecifier {};
Richard Trieue7f7ed22017-02-22 01:11:25 +00003325}
Richard Trieu73cf9242017-11-04 01:20:50 +00003326#endif
3327} // namespace SelfReference
Richard Trieue7f7ed22017-02-22 01:11:25 +00003328
3329namespace FriendFunction {
3330#if defined(FIRST)
3331void F(int = 0);
3332struct S { friend void F(int); };
3333#elif defined(SECOND)
3334void F(int);
3335struct S { friend void F(int); };
3336#else
3337S s;
3338#endif
3339
3340#if defined(FIRST)
3341void G(int = 0);
3342struct T {
3343 friend void G(int);
3344
3345 private:
3346};
3347#elif defined(SECOND)
3348void G(int);
3349struct T {
3350 friend void G(int);
3351
3352 public:
3353};
3354#else
3355T t;
3356// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3357// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3358#endif
3359} // namespace FriendFunction
3360
3361namespace ImplicitDecl {
3362#if defined(FIRST)
3363struct S { };
3364void S_Constructors() {
3365 // Trigger creation of implicit contructors
3366 S foo;
3367 S bar = foo;
3368 S baz(bar);
3369}
3370#elif defined(SECOND)
3371struct S { };
3372#else
3373S s;
3374#endif
3375
3376#if defined(FIRST)
3377struct T {
3378 private:
3379};
3380void T_Constructors() {
3381 // Trigger creation of implicit contructors
3382 T foo;
3383 T bar = foo;
3384 T baz(bar);
3385}
3386#elif defined(SECOND)
3387struct T {
3388 public:
3389};
3390#else
3391T t;
3392// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
3393// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
3394#endif
3395
Richard Trieu73cf9242017-11-04 01:20:50 +00003396} // namespace ImplicitDecl
Richard Trieue7f7ed22017-02-22 01:11:25 +00003397
3398namespace TemplatedClass {
3399#if defined(FIRST)
3400template <class>
3401struct S {};
3402#elif defined(SECOND)
3403template <class>
3404struct S {};
3405#else
3406S<int> s;
3407#endif
3408
3409#if defined(FIRST)
3410template <class>
3411struct T {
3412 private:
3413};
3414#elif defined(SECOND)
3415template <class>
3416struct T {
3417 public:
3418};
3419#else
3420T<int> t;
3421// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3422// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3423#endif
3424} // namespace TemplatedClass
3425
3426namespace TemplateClassWithField {
3427#if defined(FIRST)
3428template <class A>
3429struct S {
3430 A a;
3431};
3432#elif defined(SECOND)
3433template <class A>
3434struct S {
3435 A a;
3436};
3437#else
3438S<int> s;
3439#endif
3440
3441#if defined(FIRST)
3442template <class A>
3443struct T {
3444 A a;
3445
3446 private:
3447};
3448#elif defined(SECOND)
3449template <class A>
3450struct T {
3451 A a;
3452
3453 public:
3454};
3455#else
3456T<int> t;
3457// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3458// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3459#endif
3460} // namespace TemplateClassWithField
3461
3462namespace TemplateClassWithTemplateField {
3463#if defined(FIRST)
3464template <class A>
3465class WrapperS;
3466template <class A>
3467struct S {
3468 WrapperS<A> a;
3469};
3470#elif defined(SECOND)
3471template <class A>
3472class WrapperS;
3473template <class A>
3474struct S {
3475 WrapperS<A> a;
3476};
3477#else
3478template <class A>
3479class WrapperS{};
3480S<int> s;
3481#endif
3482
3483#if defined(FIRST)
3484template <class A>
3485class WrapperT;
3486template <class A>
3487struct T {
3488 WrapperT<A> a;
3489
3490 public:
3491};
3492#elif defined(SECOND)
3493template <class A>
3494class WrapperT;
3495template <class A>
3496struct T {
3497 WrapperT<A> a;
3498
3499 private:
3500};
3501#else
3502template <class A>
3503class WrapperT{};
3504T<int> t;
3505// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3506// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3507#endif
3508} // namespace TemplateClassWithTemplateField
3509
3510namespace EnumWithForwardDeclaration {
3511#if defined(FIRST)
3512enum E : int;
3513struct S {
3514 void get(E) {}
3515};
3516#elif defined(SECOND)
3517enum E : int { A, B };
3518struct S {
3519 void get(E) {}
3520};
3521#else
3522S s;
3523#endif
3524
3525#if defined(FIRST)
3526struct T {
3527 void get(E) {}
3528 public:
3529};
3530#elif defined(SECOND)
3531struct T {
3532 void get(E) {}
3533 private:
3534};
3535#else
3536T t;
3537// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3538// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3539#endif
3540} // namespace EnumWithForwardDeclaration
3541
3542namespace StructWithForwardDeclaration {
3543#if defined(FIRST)
3544struct P {};
3545struct S {
3546 struct P *ptr;
3547};
3548#elif defined(SECOND)
3549struct S {
3550 struct P *ptr;
3551};
3552#else
3553S s;
3554#endif
3555
3556#if defined(FIRST)
3557struct Q {};
3558struct T {
3559 struct Q *ptr;
3560 public:
3561};
3562#elif defined(SECOND)
3563struct T {
3564 struct Q *ptr;
3565 private:
3566};
3567#else
3568T t;
3569// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3570// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3571#endif
3572} // namespace StructWithForwardDeclaration
3573
3574namespace StructWithForwardDeclarationNoDefinition {
3575#if defined(FIRST)
3576struct P;
3577struct S {
3578 struct P *ptr;
3579};
3580#elif defined(SECOND)
3581struct S {
3582 struct P *ptr;
3583};
3584#else
3585S s;
3586#endif
3587
3588#if defined(FIRST)
3589struct Q;
3590struct T {
3591 struct Q *ptr;
3592
3593 public:
3594};
3595#elif defined(SECOND)
3596struct T {
3597 struct Q *ptr;
3598
3599 private:
3600};
3601#else
3602T t;
3603// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3604// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3605#endif
3606} // namespace StructWithForwardDeclarationNoDefinition
3607
Richard Trieufe564052017-04-20 02:53:53 +00003608namespace LateParsedDefaultArgument {
3609#if defined(FIRST)
3610template <typename T>
3611struct S {
3612 struct R {
3613 void foo(T x = 0) {}
3614 };
3615};
3616#elif defined(SECOND)
3617#else
3618void run() {
3619 S<int>::R().foo();
3620}
3621#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003622} // namespace LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00003623
3624namespace LateParsedDefaultArgument {
3625#if defined(FIRST)
3626template <typename alpha> struct Bravo {
3627 void charlie(bool delta = false) {}
3628};
3629typedef Bravo<char> echo;
3630echo foxtrot;
3631
3632Bravo<char> golf;
3633#elif defined(SECOND)
3634#else
3635#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003636} // LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00003637
Richard Trieu157ed942017-04-28 22:03:28 +00003638namespace DifferentParameterNameInTemplate {
3639#if defined(FIRST) || defined(SECOND)
3640template <typename T>
3641struct S {
3642 typedef T Type;
3643
3644 static void Run(const Type *name_one);
3645};
3646
3647template <typename T>
3648void S<T>::Run(const T *name_two) {}
3649
3650template <typename T>
3651struct Foo {
3652 ~Foo() { Handler::Run(nullptr); }
3653 Foo() {}
3654
3655 class Handler : public S<T> {};
3656
3657 void Get(typename Handler::Type *x = nullptr) {}
3658 void Add() { Handler::Run(nullptr); }
3659};
3660#endif
3661
3662#if defined(FIRST)
3663struct Beta;
3664
3665struct Alpha {
3666 Alpha();
3667 void Go() { betas.Get(); }
3668 Foo<Beta> betas;
3669};
3670
3671#elif defined(SECOND)
3672struct Beta {};
3673
3674struct BetaHelper {
3675 void add_Beta() { betas.Add(); }
3676 Foo<Beta> betas;
3677};
3678
3679#else
3680Alpha::Alpha() {}
3681#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003682} // DifferentParameterNameInTemplate
Richard Trieu157ed942017-04-28 22:03:28 +00003683
Richard Trieu02552272017-05-02 23:58:52 +00003684namespace ParameterTest {
3685#if defined(FIRST)
3686class X {};
3687template <typename G>
3688class S {
3689 public:
3690 typedef G Type;
3691 static inline G *Foo(const G *a, int * = nullptr);
3692};
3693
3694template<typename G>
3695G* S<G>::Foo(const G* aaaa, int*) {}
3696#elif defined(SECOND)
3697template <typename G>
3698class S {
3699 public:
3700 typedef G Type;
3701 static inline G *Foo(const G *a, int * = nullptr);
3702};
3703
3704template<typename G>
3705G* S<G>::Foo(const G* asdf, int*) {}
3706#else
3707S<X> s;
3708#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003709} // ParameterTest
Richard Trieu02552272017-05-02 23:58:52 +00003710
Richard Trieub35ef2a2017-05-09 03:24:34 +00003711namespace MultipleTypedefs {
3712#if defined(FIRST)
3713typedef int B1;
3714typedef B1 A1;
3715struct S1 {
3716 A1 x;
3717};
3718#elif defined(SECOND)
3719typedef int A1;
3720struct S1 {
3721 A1 x;
3722};
3723#else
3724S1 s1;
3725#endif
3726
3727#if defined(FIRST)
3728struct T2 { int x; };
3729typedef T2 B2;
3730typedef B2 A2;
3731struct S2 {
3732 T2 x;
3733};
3734#elif defined(SECOND)
3735struct T2 { int x; };
3736typedef T2 A2;
3737struct S2 {
3738 T2 x;
3739};
3740#else
3741S2 s2;
3742#endif
Richard Trieu3e03d3e2017-06-29 22:53:04 +00003743
3744#if defined(FIRST)
3745using A3 = const int;
3746using B3 = volatile A3;
3747struct S3 {
3748 B3 x = 1;
3749};
3750#elif defined(SECOND)
3751using A3 = volatile const int;
3752using B3 = A3;
3753struct S3 {
3754 B3 x = 1;
3755};
3756#else
3757S3 s3;
3758#endif
Richard Trieucaaccee2018-04-12 02:26:49 +00003759
3760#if defined(FIRST)
3761using A4 = int;
3762using B4 = A4;
3763struct S4 {
3764 B4 x;
3765};
3766#elif defined(SECOND)
3767using A4 = int;
3768using B4 = ::MultipleTypedefs::A4;
3769struct S4 {
3770 B4 x;
3771};
3772#else
3773S4 s4;
3774#endif
3775
3776#if defined(FIRST)
3777using A5 = int;
3778using B5 = MultipleTypedefs::A5;
3779struct S5 {
3780 B5 x;
3781};
3782#elif defined(SECOND)
3783using A5 = int;
3784using B5 = ::MultipleTypedefs::A5;
3785struct S5 {
3786 B5 x;
3787};
3788#else
3789S5 s5;
3790#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003791} // MultipleTypedefs
3792
3793namespace DefaultArguments {
3794#if defined(FIRST)
3795template <typename T>
3796struct S {
3797 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00003798 void foo(T x = 0);
Richard Trieu73cf9242017-11-04 01:20:50 +00003799 };
3800};
3801#elif defined(SECOND)
3802template <typename T>
3803struct S {
3804 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00003805 void foo(T x = 1);
Richard Trieu73cf9242017-11-04 01:20:50 +00003806 };
3807};
3808#else
3809void run() {
3810 S<int>::R().foo();
Richard Trieub35ef2a2017-05-09 03:24:34 +00003811}
Richard Trieu73cf9242017-11-04 01:20:50 +00003812// 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}}
3813// expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}}
3814#endif
3815
3816#if defined(FIRST)
3817template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00003818 void charlie(bool delta = false);
Richard Trieu73cf9242017-11-04 01:20:50 +00003819};
3820typedef Bravo<char> echo;
3821echo foxtrot;
3822#elif defined(SECOND)
3823template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00003824 void charlie(bool delta = (false));
Richard Trieu73cf9242017-11-04 01:20:50 +00003825};
3826typedef Bravo<char> echo;
3827echo foxtrot;
3828#else
3829Bravo<char> golf;
3830// 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}}
3831// expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}}
3832#endif
3833} // namespace DefaultArguments
Richard Trieu02552272017-05-02 23:58:52 +00003834
Richard Trieue6caa262017-12-23 00:41:01 +00003835namespace FunctionDecl {
3836#if defined(FIRST)
3837struct S1 {};
3838S1 s1a;
3839#elif defined(SECOND)
3840struct S1 {};
3841#else
3842S1 s1;
3843#endif
3844
3845#if defined(FIRST)
3846struct S2 {
3847 S2() = default;
3848};
3849S2 s2a = S2();
3850#elif defined(SECOND)
3851struct S2 {
3852 S2() = default;
3853};
3854#else
3855S2 s2;
3856#endif
3857
3858#if defined(FIRST)
3859struct S3 {
3860 S3() = delete;
3861};
3862S3* s3c;
3863#elif defined(SECOND)
3864struct S3 {
3865 S3() = delete;
3866};
3867#else
3868S3* s3;
3869#endif
3870
3871#if defined(FIRST) || defined(SECOND)
3872int F1(int x, float y = 2.7) { return 1; }
3873#else
3874int I1 = F1(1);
3875#endif
3876
3877#if defined(FIRST)
3878int F2() { return 1; }
3879#elif defined(SECOND)
3880double F2() { return 1; }
3881#else
3882int I2 = F2();
3883// expected-error@-1 {{call to 'F2' is ambiguous}}
3884// expected-note@first.h:* {{candidate function}}
3885// expected-note@second.h:* {{candidate function}}
3886#endif
3887
3888#if defined(FIRST)
3889int F3(float) { return 1; }
3890#elif defined(SECOND)
3891int F3(double) { return 1; }
3892#else
3893int I3 = F3(1);
3894// expected-error@-1 {{call to 'F3' is ambiguous}}
3895// expected-note@first.h:* {{candidate function}}
3896// expected-note@second.h:* {{candidate function}}
3897#endif
3898
3899#if defined(FIRST)
3900int F4(int x) { return 1; }
3901#elif defined(SECOND)
3902int F4(int y) { return 1; }
3903#else
3904int I4 = F4(1);
3905// expected-error@second.h:* {{'FunctionDecl::F4' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with name 'y'}}
3906// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with name 'x'}}
3907#endif
3908
3909#if defined(FIRST)
3910int F5(int x) { return 1; }
3911#elif defined(SECOND)
3912int F5(int x = 1) { return 1; }
3913#else
3914int I5 = F6(1);
3915// 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}}
3916// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a default argument}}
3917#endif
3918
3919#if defined(FIRST)
3920int F6(int x = 2) { return 1; }
3921#elif defined(SECOND)
3922int F6(int x = 1) { return 1; }
3923#else
3924int I6 = F6(1);
3925// 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}}
3926// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a different default argument}}
3927#endif
3928
3929using I = int;
3930#if defined(FIRST)
3931I F7() { return 0; }
3932#elif defined(SECOND)
3933int F7() { return 0; }
3934#else
3935int I7 = F7();
3936// expected-error@second.h:* {{'FunctionDecl::F7' has different definitions in different modules; definition in module 'SecondModule' first difference is return type is 'int'}}
3937// expected-note@first.h:* {{but in 'FirstModule' found different return type 'FunctionDecl::I' (aka 'int')}}
3938#endif
3939
3940#if defined(FIRST)
3941int F8(int) { return 0; }
3942#elif defined(SECOND)
3943int F8(I) { return 0; }
3944#else
3945int I8 = F8(1);
3946// 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')}}
3947// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int'}}
3948#endif
3949
3950#if defined(FIRST)
3951int F9(int[1]) { return 0; }
3952#elif defined(SECOND)
3953int F9(int[2]) { return 0; }
3954#else
3955int I9 = F9(nullptr);
3956// 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]'}}
3957// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int *' decayed from 'int [1]'}}
3958#endif
3959
3960#if defined(FIRST)
3961int F10() { return 1; }
3962#elif defined(SECOND)
3963int F10() { return 2; }
3964#else
3965int I10 = F10();
3966#endif
3967// expected-error@second.h:* {{'FunctionDecl::F10' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3968// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
Richard Trieu5d014062018-06-07 00:20:58 +00003969
3970#if defined(FIRST)
3971struct S11 {
3972 template <int> void foo();
3973};
3974#elif defined(SECOND)
3975struct S11 {
3976 template <int> void foo();
3977};
3978template <int> void S11::foo() {}
3979#else
3980S11 s11;
3981#endif
3982
Richard Trieu27c1b1a2018-07-10 01:40:50 +00003983#if defined(FIRST)
3984struct S12 {
3985 void foo(int x);
3986};
3987#elif defined(SECOND)
3988struct S12 {
3989 void foo(int x);
3990};
3991void S12::foo(int y) {}
3992#else
3993S12 s12;
3994#endif
3995
3996#if defined(FIRST)
3997struct S13 {
3998 void foo(int x);
3999};
4000void S13::foo(int y) {}
4001#elif defined(SECOND)
4002struct S13 {
4003 void foo(int x);
4004};
4005void S13::foo(int y) {}
4006#else
4007S13 s13;
4008#endif
Richard Trieue6caa262017-12-23 00:41:01 +00004009} // namespace FunctionDecl
4010
Richard Trieu4d06bef2018-02-13 19:53:40 +00004011namespace DeclTemplateArguments {
4012#if defined(FIRST)
4013int foo() { return 1; }
4014int bar() { return foo(); }
4015#elif defined(SECOND)
4016template <class T = int>
4017int foo() { return 2; }
4018int bar() { return foo<>(); }
4019#else
4020int num = bar();
4021// expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
4022// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
4023#endif
4024}
4025
Richard Trieue7f7ed22017-02-22 01:11:25 +00004026// Keep macros contained to one file.
4027#ifdef FIRST
4028#undef FIRST
4029#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004030
Richard Trieue7f7ed22017-02-22 01:11:25 +00004031#ifdef SECOND
4032#undef SECOND
4033#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004034
4035#ifdef ACCESS
4036#undef ACCESS
4037#endif