blob: 9cb177fbfce84d7aa34959c31a8f0f00f4e29291 [file] [log] [blame]
Richard Trieue7f7ed22017-02-22 01:11:25 +00001// Clear and create directories
2// RUN: rm -rf %t
3// RUN: mkdir %t
4// RUN: mkdir %t/cache
5// RUN: mkdir %t/Inputs
6
7// Build first header file
8// RUN: echo "#define FIRST" >> %t/Inputs/first.h
9// RUN: cat %s >> %t/Inputs/first.h
10
11// Build second header file
12// RUN: echo "#define SECOND" >> %t/Inputs/second.h
13// RUN: cat %s >> %t/Inputs/second.h
14
Richard Trieu73cf9242017-11-04 01:20:50 +000015// Test that each header can compile
16// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++1z %t/Inputs/first.h
17// RUN: %clang_cc1 -fsyntax-only -x c++ -std=c++1z %t/Inputs/second.h
18
Richard Trieue7f7ed22017-02-22 01:11:25 +000019// Build module map file
20// RUN: echo "module FirstModule {" >> %t/Inputs/module.map
21// RUN: echo " header \"first.h\"" >> %t/Inputs/module.map
22// RUN: echo "}" >> %t/Inputs/module.map
23// RUN: echo "module SecondModule {" >> %t/Inputs/module.map
24// RUN: echo " header \"second.h\"" >> %t/Inputs/module.map
25// RUN: echo "}" >> %t/Inputs/module.map
26
27// Run test
Richard Trieu639d7b62017-02-22 22:22:42 +000028// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z
Richard Trieue7f7ed22017-02-22 01:11:25 +000029
30#if !defined(FIRST) && !defined(SECOND)
31#include "first.h"
32#include "second.h"
33#endif
34
Richard Trieu73cf9242017-11-04 01:20:50 +000035// Used for testing
36#if defined(FIRST)
37#define ACCESS public:
38#elif defined(SECOND)
39#define ACCESS private:
40#endif
41
Richard Trieue7f7ed22017-02-22 01:11:25 +000042namespace AccessSpecifiers {
43#if defined(FIRST)
44struct S1 {
45};
46#elif defined(SECOND)
47struct S1 {
48 private:
49};
50#else
51S1 s1;
52// expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
53// expected-note@first.h:* {{but in 'FirstModule' found end of class}}
54#endif
55
56#if defined(FIRST)
57struct S2 {
58 public:
59};
60#elif defined(SECOND)
61struct S2 {
62 protected:
63};
64#else
65S2 s2;
66// expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}}
67// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
68#endif
Richard Trieu73cf9242017-11-04 01:20:50 +000069
70#define DECLS \
71public: \
72private: \
73protected:
74
75#if defined(FIRST) || defined(SECOND)
76struct Valid1 {
77 DECLS
78};
79#else
80Valid1 v1;
81#endif
82
83#if defined(FIRST) || defined(SECOND)
84struct Invalid1 {
85 DECLS
86 ACCESS
87};
88#else
89Invalid1 i1;
90// expected-error@second.h:* {{'AccessSpecifiers::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
91// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
92#endif
93
94#undef DECLS
Richard Trieue7f7ed22017-02-22 01:11:25 +000095} // namespace AccessSpecifiers
96
Richard Trieu639d7b62017-02-22 22:22:42 +000097namespace StaticAssert {
98#if defined(FIRST)
99struct S1 {
100 static_assert(1 == 1, "First");
101};
102#elif defined(SECOND)
103struct S1 {
104 static_assert(1 == 1, "Second");
105};
106#else
107S1 s1;
108// expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}}
109// expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}}
110#endif
111
112#if defined(FIRST)
113struct S2 {
114 static_assert(2 == 2, "Message");
115};
116#elif defined(SECOND)
117struct S2 {
118 static_assert(2 == 2);
119};
120#else
121S2 s2;
122// expected-error@second.h:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}}
123// expected-note@first.h:* {{but in 'FirstModule' found static assert with message}}
124#endif
125
126#if defined(FIRST)
127struct S3 {
128 static_assert(3 == 3, "Message");
129};
130#elif defined(SECOND)
131struct S3 {
132 static_assert(3 != 4, "Message");
133};
134#else
135S3 s3;
136// expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}}
137// expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}}
138#endif
139
140#if defined(FIRST)
141struct S4 {
142 static_assert(4 == 4, "Message");
143};
144#elif defined(SECOND)
145struct S4 {
146 public:
147};
148#else
149S4 s4;
150// expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
151// expected-note@first.h:* {{but in 'FirstModule' found static assert}}
152#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000153
154#define DECLS \
155 static_assert(4 == 4, "Message"); \
156 static_assert(5 == 5);
157
158#if defined(FIRST) || defined(SECOND)
159struct Valid1 {
160 DECLS
161};
162#else
163Valid1 v1;
164#endif
165
166#if defined(FIRST) || defined(SECOND)
167struct Invalid1 {
168 DECLS
169 ACCESS
170};
171#else
172Invalid1 i1;
173// expected-error@second.h:* {{'StaticAssert::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
174// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
175#endif
176#undef DECLS
177} // namespace StaticAssert
Richard Trieu639d7b62017-02-22 22:22:42 +0000178
Richard Trieud0786092017-02-23 00:23:01 +0000179namespace Field {
180#if defined(FIRST)
181struct S1 {
182 int x;
183 private:
184 int y;
185};
186#elif defined(SECOND)
187struct S1 {
188 int x;
189 int y;
190};
191#else
192S1 s1;
193// expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
194// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
195#endif
196
197#if defined(FIRST)
198struct S2 {
199 int x;
200 int y;
201};
202#elif defined(SECOND)
203struct S2 {
204 int y;
205 int x;
206};
207#else
208S2 s2;
209// expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
210// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
211#endif
Richard Trieubcaaf962017-02-23 03:25:57 +0000212
213#if defined(FIRST)
214struct S3 {
215 double x;
216};
217#elif defined(SECOND)
218struct S3 {
219 int x;
220};
221#else
222S3 s3;
223// expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}}
224// expected-note@second.h:* {{declaration of 'x' does not match}}
225#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000226
227#if defined(FIRST)
228typedef int A;
229struct S4 {
230 A x;
231};
232
233struct S5 {
234 A x;
235};
236#elif defined(SECOND)
237typedef int B;
238struct S4 {
239 B x;
240};
241
242struct S5 {
243 int x;
244};
245#else
246S4 s4;
Alex Lorenz76377dc2017-03-10 15:04:58 +0000247// expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'Field::B' (aka 'int')}}
248// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000249
250S5 s5;
251// expected-error@second.h:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}}
Alex Lorenz76377dc2017-03-10 15:04:58 +0000252// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000253#endif
254
Richard Trieu93772fc2017-02-24 20:59:28 +0000255#if defined(FIRST)
256struct S6 {
257 unsigned x;
258};
259#elif defined(SECOND)
260struct S6 {
261 unsigned x : 1;
262};
263#else
264S6 s6;
265// expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}}
266// expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}}
267#endif
268
269#if defined(FIRST)
270struct S7 {
271 unsigned x : 2;
272};
273#elif defined(SECOND)
274struct S7 {
275 unsigned x : 1;
276};
277#else
278S7 s7;
279// expected-error@second.h:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}}
280// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
281#endif
282
283#if defined(FIRST)
284struct S8 {
285 unsigned x : 2;
286};
287#elif defined(SECOND)
288struct S8 {
289 unsigned x : 1 + 1;
290};
291#else
292S8 s8;
293// expected-error@second.h:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}}
294// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
295#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000296
Richard Trieu8d543e22017-02-24 23:35:37 +0000297#if defined(FIRST)
298struct S9 {
299 mutable int x;
300};
301#elif defined(SECOND)
302struct S9 {
303 int x;
304};
305#else
306S9 s9;
307// expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
308// expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}}
309#endif
310
311#if defined(FIRST)
312struct S10 {
313 unsigned x = 5;
314};
315#elif defined(SECOND)
316struct S10 {
317 unsigned x;
318};
319#else
320S10 s10;
321// expected-error@second.h:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initalizer}}
322// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}}
323#endif
324
325#if defined(FIRST)
326struct S11 {
327 unsigned x = 5;
328};
329#elif defined(SECOND)
330struct S11 {
331 unsigned x = 7;
332};
333#else
334S11 s11;
335// expected-error@second.h:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}}
336// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
337#endif
338
Richard Trieu02552272017-05-02 23:58:52 +0000339#if defined(FIRST)
340struct S12 {
341 unsigned x[5];
342};
343#elif defined(SECOND)
344struct S12 {
345 unsigned x[7];
346};
347#else
348S12 s12;
349// expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}}
350// expected-note@second.h:* {{declaration of 'x' does not match}}
351#endif
352
353#if defined(FIRST)
354struct S13 {
355 unsigned x[7];
356};
357#elif defined(SECOND)
358struct S13 {
359 double x[7];
360};
361#else
362S13 s13;
363// expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}}
364// expected-note@second.h:* {{declaration of 'x' does not match}}
365#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000366
367#define DECLS \
368 int a; \
369 int b : 3; \
370 unsigned c : 1 + 2; \
371 s d; \
372 double e = 1.0; \
373 long f[5];
374
375#if defined(FIRST) || defined(SECOND)
376typedef short s;
377#endif
378
379#if defined(FIRST) || defined(SECOND)
380struct Valid1 {
381 DECLS
382};
383#else
384Valid1 v1;
385#endif
386
387#if defined(FIRST) || defined(SECOND)
388struct Invalid1 {
389 DECLS
390 ACCESS
391};
392#else
393Invalid1 i1;
394// expected-error@second.h:* {{'Field::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
395// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
396#endif
397#undef DECLS
Richard Trieud0786092017-02-23 00:23:01 +0000398} // namespace Field
399
Richard Trieu48143742017-02-28 21:24:38 +0000400namespace Method {
401#if defined(FIRST)
402struct S1 {
403 void A() {}
404};
405#elif defined(SECOND)
406struct S1 {
407 private:
408 void A() {}
409};
410#else
411S1 s1;
412// expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
413// expected-note@first.h:* {{but in 'FirstModule' found method}}
414#endif
415
416#if defined(FIRST)
417struct S2 {
418 void A() {}
419 void B() {}
420};
421#elif defined(SECOND)
422struct S2 {
423 void B() {}
424 void A() {}
425};
426#else
427S2 s2;
428// expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
429// expected-note@first.h:* {{but in 'FirstModule' found method 'A'}}
430#endif
Richard Trieu583e2c12017-03-04 00:08:58 +0000431
432#if defined(FIRST)
433struct S3 {
434 static void A() {}
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000435 void A(int) {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000436};
437#elif defined(SECOND)
438struct S3 {
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000439 void A(int) {}
440 static void A() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000441};
442#else
443S3 s3;
444// expected-error@second.h:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}}
445// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}}
446#endif
447
448#if defined(FIRST)
449struct S4 {
450 virtual void A() {}
451 void B() {}
452};
453#elif defined(SECOND)
454struct S4 {
455 void A() {}
456 virtual void B() {}
457};
458#else
459S4 s4;
460// expected-error@second.h:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}}
461// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}}
462#endif
463
464#if defined(FIRST)
465struct S5 {
466 virtual void A() = 0;
467 virtual void B() {};
468};
469#elif defined(SECOND)
470struct S5 {
471 virtual void A() {}
472 virtual void B() = 0;
473};
474#else
475S5 *s5;
476// expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
477// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}}
478#endif
479
480#if defined(FIRST)
481struct S6 {
482 inline void A() {}
483};
484#elif defined(SECOND)
485struct S6 {
486 void A() {}
487};
488#else
489S6 s6;
490// expected-error@second.h:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}}
491// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}}
492#endif
493
494#if defined(FIRST)
495struct S7 {
496 void A() volatile {}
497 void A() {}
498};
499#elif defined(SECOND)
500struct S7 {
501 void A() {}
502 void A() volatile {}
503};
504#else
505S7 s7;
506// expected-error@second.h:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}}
507// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}}
508#endif
509
510#if defined(FIRST)
511struct S8 {
512 void A() const {}
513 void A() {}
514};
515#elif defined(SECOND)
516struct S8 {
517 void A() {}
518 void A() const {}
519};
520#else
521S8 s8;
522// expected-error@second.h:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}}
523// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}}
524#endif
525
Richard Trieu02552272017-05-02 23:58:52 +0000526#if defined(FIRST)
527struct S9 {
528 void A(int x) {}
529 void A(int x, int y) {}
530};
531#elif defined(SECOND)
532struct S9 {
533 void A(int x, int y) {}
534 void A(int x) {}
535};
536#else
537S9 s9;
538// expected-error@second.h:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}}
539// expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}}
540#endif
541
542#if defined(FIRST)
543struct S10 {
544 void A(int x) {}
545 void A(float x) {}
546};
547#elif defined(SECOND)
548struct S10 {
549 void A(float x) {}
550 void A(int x) {}
551};
552#else
553S10 s10;
554// expected-error@second.h:* {{'Method::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'float'}}
555// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}}
556#endif
557
558#if defined(FIRST)
559struct S11 {
Richard Trieue6caa262017-12-23 00:41:01 +0000560 void A(int x);
Richard Trieu02552272017-05-02 23:58:52 +0000561};
562#elif defined(SECOND)
563struct S11 {
Richard Trieue6caa262017-12-23 00:41:01 +0000564 void A(int y);
Richard Trieu02552272017-05-02 23:58:52 +0000565};
566#else
567S11 s11;
568// expected-error@second.h:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}}
569// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}}
570#endif
571
572#if defined(FIRST)
573struct S12 {
Richard Trieue6caa262017-12-23 00:41:01 +0000574 void A(int x);
Richard Trieu02552272017-05-02 23:58:52 +0000575};
576#elif defined(SECOND)
577struct S12 {
Richard Trieue6caa262017-12-23 00:41:01 +0000578 void A(int x = 1);
Richard Trieu02552272017-05-02 23:58:52 +0000579};
580#else
581S12 s12;
Richard Trieu6e13ff32017-06-16 02:44:29 +0000582// expected-error@second.h:* {{'Method::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter without a default argument}}
583// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}}
Richard Trieu02552272017-05-02 23:58:52 +0000584#endif
585
586#if defined(FIRST)
587struct S13 {
Richard Trieue6caa262017-12-23 00:41:01 +0000588 void A(int x = 1 + 0);
Richard Trieu02552272017-05-02 23:58:52 +0000589};
590#elif defined(SECOND)
591struct S13 {
Richard Trieue6caa262017-12-23 00:41:01 +0000592 void A(int x = 1);
Richard Trieu02552272017-05-02 23:58:52 +0000593};
594#else
595S13 s13;
Richard Trieu6e13ff32017-06-16 02:44:29 +0000596// expected-error@second.h:* {{'Method::S13' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter with a default argument}}
597// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a different default argument}}
Richard Trieu02552272017-05-02 23:58:52 +0000598#endif
599
600#if defined(FIRST)
601struct S14 {
Richard Trieue6caa262017-12-23 00:41:01 +0000602 void A(int x[2]);
Richard Trieu02552272017-05-02 23:58:52 +0000603};
604#elif defined(SECOND)
605struct S14 {
Richard Trieue6caa262017-12-23 00:41:01 +0000606 void A(int x[3]);
Richard Trieu02552272017-05-02 23:58:52 +0000607};
608#else
609S14 s14;
610// expected-error@second.h:* {{'Method::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [3]'}}
611// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}}
612#endif
Richard Trieu9747a7c2017-07-14 01:36:41 +0000613
614#if defined(FIRST)
615struct S15 {
616 int A() { return 0; }
617};
618#elif defined(SECOND)
619struct S15 {
620 long A() { return 0; }
621};
622#else
623S15 s15;
624// expected-error@first.h:* {{'Method::S15::A' from module 'FirstModule' is not present in definition of 'Method::S15' in module 'SecondModule'}}
625// expected-note@second.h:* {{declaration of 'A' does not match}}
626#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000627
628#define DECLS \
629 void A(); \
630 static void B(); \
631 virtual void C(); \
632 virtual void D() = 0; \
633 inline void E(); \
634 void F() const; \
635 void G() volatile; \
636 void H(int x); \
637 void I(int x = 5 + 5); \
638 void J(int); \
639 void K(int x[2]); \
640 int L();
641
642#if defined(FIRST) || defined(SECOND)
643struct Valid1 {
644 DECLS
645};
646#else
647Valid1* v1;
648#endif
649
650#if defined(FIRST) || defined(SECOND)
651struct Invalid1 {
652 DECLS
653 ACCESS
654};
655#else
656Invalid1* i1;
657// expected-error@second.h:* {{'Method::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
658// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
659#endif
660#undef DECLS
Richard Trieu48143742017-02-28 21:24:38 +0000661} // namespace Method
662
Richard Trieu1c71d512017-07-15 02:55:13 +0000663namespace Constructor {
664#if defined(FIRST)
665struct S1 {
666 S1() {}
667 void foo() {}
668};
669#elif defined(SECOND)
670struct S1 {
671 void foo() {}
672 S1() {}
673};
674#else
675S1 s1;
676// expected-error@second.h:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}}
677// expected-note@first.h:* {{but in 'FirstModule' found constructor}}
678#endif
679
680#if defined(FIRST)
681struct S2 {
682 S2(int) {}
683 S2(int, int) {}
684};
685#elif defined(SECOND)
686struct S2 {
687 S2(int, int) {}
688 S2(int) {}
689};
690#else
691S2* s2;
692// expected-error@second.h:* {{'Constructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor that has 2 parameters}}
693// expected-note@first.h:* {{but in 'FirstModule' found constructor that has 1 parameter}}
694#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000695
696#define DECLS(CLASS) \
697 CLASS(int); \
698 CLASS(double); \
699 CLASS(int, int);
700
701#if defined(FIRST) || defined(SECOND)
702struct Valid1 {
703 DECLS(Valid1)
704};
705#else
706Valid1* v1;
707#endif
708
709#if defined(FIRST) || defined(SECOND)
710struct Invalid1 {
711 DECLS(Invalid1)
712 ACCESS
713};
714#else
715Invalid1* i1;
716// expected-error@second.h:* {{'Constructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
717// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
718#endif
719#undef DECLS
Richard Trieu1c71d512017-07-15 02:55:13 +0000720} // namespace Constructor
721
722namespace Destructor {
723#if defined(FIRST)
724struct S1 {
725 ~S1() {}
726 S1() {}
727};
728#elif defined(SECOND)
729struct S1 {
730 S1() {}
731 ~S1() {}
732};
733#else
734S1 s1;
735// expected-error@second.h:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}}
736// expected-note@first.h:* {{but in 'FirstModule' found destructor}}
737#endif
738
739#if defined(FIRST)
740struct S2 {
741 virtual ~S2() {}
742 void foo() {}
743};
744#elif defined(SECOND)
745struct S2 {
746 ~S2() {}
747 virtual void foo() {}
748};
749#else
750S2 s2;
751// expected-error@second.h:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}}
752// expected-note@first.h:* {{but in 'FirstModule' found destructor is virtual}}
753#endif
754
Richard Trieu73cf9242017-11-04 01:20:50 +0000755#if defined(FIRST) || defined(SECOND)
756struct Valid1 {
757 ~Valid1();
Richard Trieue7f7ed22017-02-22 01:11:25 +0000758};
Richard Trieu73cf9242017-11-04 01:20:50 +0000759#else
760Valid1 v1;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000761#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000762
763#if defined(FIRST) || defined(SECOND)
764struct Invalid1 {
765 ~Invalid1();
766 ACCESS
767};
768#else
769Invalid1 i1;
770// expected-error@second.h:* {{'Destructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
771// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
772#endif
773
774#if defined(FIRST) || defined(SECOND)
775struct Valid2 {
776 virtual ~Valid2();
777};
778#else
779Valid2 v2;
780#endif
781
782#if defined(FIRST) || defined(SECOND)
783struct Invalid2 {
784 virtual ~Invalid2();
785 ACCESS
786};
787#else
788Invalid2 i2;
789// expected-error@second.h:* {{'Destructor::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
790// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
791#endif
792} // namespace Destructor
Richard Trieue7f7ed22017-02-22 01:11:25 +0000793
Richard Trieu33562c22017-03-08 00:13:19 +0000794namespace TypeDef {
795#if defined(FIRST)
796struct S1 {
797 typedef int a;
798};
799#elif defined(SECOND)
800struct S1 {
801 typedef double a;
802};
803#else
804S1 s1;
805// expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
806// expected-note@second.h:* {{declaration of 'a' does not match}}
807#endif
808
809#if defined(FIRST)
810struct S2 {
811 typedef int a;
812};
813#elif defined(SECOND)
814struct S2 {
815 typedef int b;
816};
817#else
818S2 s2;
819// expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
820// expected-note@second.h:* {{definition has no member 'a'}}
821#endif
822
823#if defined(FIRST)
824typedef int T;
825struct S3 {
826 typedef T a;
827};
828#elif defined(SECOND)
829typedef double T;
830struct S3 {
831 typedef T a;
832};
833#else
834S3 s3;
835// expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
836// expected-note@second.h:* {{declaration of 'a' does not match}}
837#endif
Richard Trieu11d566a2017-06-12 21:58:22 +0000838
839#if defined(FIRST)
840struct S4 {
841 typedef int a;
842 typedef int b;
843};
844#elif defined(SECOND)
845struct S4 {
846 typedef int b;
847 typedef int a;
848};
849#else
850S4 s4;
851// expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}}
852// expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}}
853#endif
854
855#if defined(FIRST)
856struct S5 {
857 typedef int a;
858 typedef int b;
859 int x;
860};
861#elif defined(SECOND)
862struct S5 {
863 int x;
864 typedef int b;
865 typedef int a;
866};
867#else
868S5 s5;
869// expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
870// expected-note@first.h:* {{but in 'FirstModule' found typedef}}
871#endif
872
873#if defined(FIRST)
874typedef float F;
875struct S6 {
876 typedef int a;
877 typedef F b;
878};
879#elif defined(SECOND)
880struct S6 {
881 typedef int a;
882 typedef float b;
883};
884#else
885S6 s6;
886// expected-error@second.h:* {{'TypeDef::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef 'b' with underlying type 'float'}}
887// expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}}
888#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000889
890#define DECLS \
891 typedef int A; \
892 typedef double B; \
893 typedef I C;
894
895#if defined(FIRST) || defined(SECOND)
896typedef int I;
897#endif
898
899#if defined(FIRST) || defined(SECOND)
900struct Valid1 {
901 DECLS
902};
903#else
904Valid1 v1;
905#endif
906
907#if defined(FIRST) || defined(SECOND)
908struct Invalid1 {
909 DECLS
910 ACCESS
911};
912#else
913Invalid1 i1;
914// expected-error@second.h:* {{'TypeDef::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
915// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
916#endif
917#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +0000918} // namespace TypeDef
919
920namespace Using {
921#if defined(FIRST)
922struct S1 {
923 using a = int;
924};
925#elif defined(SECOND)
926struct S1 {
927 using a = double;
928};
929#else
930S1 s1;
931// expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
932// expected-note@second.h:* {{declaration of 'a' does not match}}
933#endif
934
935#if defined(FIRST)
936struct S2 {
937 using a = int;
938};
939#elif defined(SECOND)
940struct S2 {
941 using b = int;
942};
943#else
944S2 s2;
945// expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
946// expected-note@second.h:* {{definition has no member 'a'}}
947#endif
948
949#if defined(FIRST)
950typedef int T;
951struct S3 {
952 using a = T;
953};
954#elif defined(SECOND)
955typedef double T;
956struct S3 {
957 using a = T;
958};
959#else
960S3 s3;
961// expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
962// expected-note@second.h:* {{declaration of 'a' does not match}}
963#endif
Richard Trieu11d566a2017-06-12 21:58:22 +0000964
965#if defined(FIRST)
966struct S4 {
967 using a = int;
968 using b = int;
969};
970#elif defined(SECOND)
971struct S4 {
972 using b = int;
973 using a = int;
974};
975#else
976S4 s4;
977// expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}}
978// expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}}
979#endif
980
981#if defined(FIRST)
982struct S5 {
983 using a = int;
984 using b = int;
985 int x;
986};
987#elif defined(SECOND)
988struct S5 {
989 int x;
990 using b = int;
991 using a = int;
992};
993#else
994S5 s5;
995// expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
996// expected-note@first.h:* {{but in 'FirstModule' found type alias}}
997#endif
998
999#if defined(FIRST)
1000typedef float F;
1001struct S6 {
1002 using a = int;
1003 using b = F;
1004};
1005#elif defined(SECOND)
1006struct S6 {
1007 using a = int;
1008 using b = float;
1009};
1010#else
1011S6 s6;
1012// expected-error@second.h:* {{'Using::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'b' with underlying type 'float'}}
1013// expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}}
1014#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001015
1016#if defined(FIRST) || defined(SECOND)
1017using I = int;
1018#endif
1019
1020#define DECLS \
1021 using A = int; \
1022 using B = double; \
1023 using C = I;
1024
1025#if defined(FIRST) || defined(SECOND)
1026struct Valid1 {
1027 DECLS
1028};
1029#else
1030Valid1 v1;
1031#endif
1032
1033#if defined(FIRST) || defined(SECOND)
1034struct Invalid1 {
1035 DECLS
1036 ACCESS
1037};
1038#else
1039Invalid1 i1;
1040// expected-error@second.h:* {{'Using::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1041// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1042#endif
1043#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +00001044} // namespace Using
1045
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001046namespace RecordType {
1047#if defined(FIRST)
1048struct B1 {};
1049struct S1 {
1050 B1 x;
1051};
1052#elif defined(SECOND)
1053struct A1 {};
1054struct S1 {
1055 A1 x;
1056};
1057#else
1058S1 s1;
1059// expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
1060// expected-note@second.h:* {{declaration of 'x' does not match}}
1061#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001062
1063#define DECLS \
1064 Foo F;
1065
1066#if defined(FIRST) || defined(SECOND)
1067struct Foo {};
1068#endif
1069
1070#if defined(FIRST) || defined(SECOND)
1071struct Valid1 {
1072 DECLS
1073};
1074#else
1075Valid1 v1;
1076#endif
1077
1078#if defined(FIRST) || defined(SECOND)
1079struct Invalid1 {
1080 DECLS
1081 ACCESS
1082};
1083#else
1084Invalid1 i1;
1085// expected-error@second.h:* {{'RecordType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1086// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1087#endif
1088#undef DECLS
1089} // namespace RecordType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001090
1091namespace DependentType {
1092#if defined(FIRST)
1093template <class T>
1094class S1 {
1095 typename T::typeA x;
1096};
1097#elif defined(SECOND)
1098template <class T>
1099class S1 {
1100 typename T::typeB x;
1101};
1102#else
1103template<class T>
1104using U1 = S1<T>;
1105// expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
1106// expected-note@second.h:* {{declaration of 'x' does not match}}
1107#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001108
1109#define DECLS \
1110 typename T::typeA x;
1111
1112#if defined(FIRST) || defined(SECOND)
1113template <class T>
1114struct Valid1 {
1115 DECLS
1116};
1117#else
1118template <class T>
1119using V1 = Valid1<T>;
1120#endif
1121
1122#if defined(FIRST) || defined(SECOND)
1123template <class T>
1124struct Invalid1 {
1125 DECLS
1126 ACCESS
1127};
1128#else
1129template <class T>
1130using I1 = Invalid1<T>;
1131// expected-error@second.h:* {{'DependentType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1132// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1133#endif
1134#undef DECLS
1135} // namespace DependentType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001136
1137namespace ElaboratedType {
1138#if defined(FIRST)
1139namespace N1 { using type = double; }
1140struct S1 {
1141 N1::type x;
1142};
1143#elif defined(SECOND)
1144namespace N1 { using type = int; }
1145struct S1 {
1146 N1::type x;
1147};
1148#else
1149S1 s1;
1150// expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}}
1151// expected-note@second.h:* {{declaration of 'x' does not match}}
1152#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001153
1154#define DECLS \
1155 NS::type x;
1156
1157#if defined(FIRST) || defined(SECOND)
1158namespace NS { using type = float; }
1159#endif
1160
1161#if defined(FIRST) || defined(SECOND)
1162struct Valid1 {
1163 DECLS
1164};
1165#else
1166Valid1 v1;
1167#endif
1168
1169#if defined(FIRST) || defined(SECOND)
1170struct Invalid1 {
1171 DECLS
1172 ACCESS
1173};
1174#else
1175Invalid1 i1;
1176// expected-error@second.h:* {{'ElaboratedType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1177// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1178#endif
1179#undef DECLS
1180} // namespace ElaboratedType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001181
1182namespace Enum {
1183#if defined(FIRST)
1184enum A1 {};
1185struct S1 {
1186 A1 x;
1187};
1188#elif defined(SECOND)
1189enum A2 {};
1190struct S1 {
1191 A2 x;
1192};
1193#else
1194S1 s1;
1195// expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
1196// expected-note@second.h:* {{declaration of 'x' does not match}}
1197#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001198
1199#define DECLS \
1200 E e = E1;
1201
1202#if defined(FIRST) || defined(SECOND)
1203enum E { E1, E2 };
1204#endif
1205
1206#if defined(FIRST) || defined(SECOND)
1207struct Valid1 {
1208 DECLS
1209};
1210#else
1211Valid1 v1;
1212#endif
1213
1214#if defined(FIRST) || defined(SECOND)
1215struct Invalid1 {
1216 DECLS
1217 ACCESS
1218};
1219#else
1220Invalid1 i1;
1221// expected-error@second.h:* {{'Enum::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1222// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1223#endif
1224#undef DECLS
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001225}
Hans Wennborg22707762017-04-12 16:40:26 +00001226
Richard Trieuce81b192017-05-17 03:23:35 +00001227namespace NestedNamespaceSpecifier {
1228#if defined(FIRST)
1229namespace LevelA1 {
1230using Type = int;
1231}
1232
1233struct S1 {
1234 LevelA1::Type x;
1235};
1236# elif defined(SECOND)
1237namespace LevelB1 {
1238namespace LevelC1 {
1239using Type = int;
1240}
1241}
1242
1243struct S1 {
1244 LevelB1::LevelC1::Type x;
1245};
1246#else
1247S1 s1;
1248// expected-error@second.h:* {{'NestedNamespaceSpecifier::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB1::LevelC1::Type' (aka 'int')}}
1249// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
1250#endif
1251
1252#if defined(FIRST)
1253namespace LevelA2 { using Type = int; }
1254struct S2 {
1255 LevelA2::Type x;
1256};
1257# elif defined(SECOND)
1258struct S2 {
1259 int x;
1260};
1261#else
1262S2 s2;
1263// expected-error@second.h:* {{'NestedNamespaceSpecifier::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}}
1264// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
1265#endif
1266
1267namespace LevelA3 { using Type = int; }
1268namespace LevelB3 { using Type = int; }
1269#if defined(FIRST)
1270struct S3 {
1271 LevelA3::Type x;
1272};
1273# elif defined(SECOND)
1274struct S3 {
1275 LevelB3::Type x;
1276};
1277#else
1278S3 s3;
1279// expected-error@second.h:* {{'NestedNamespaceSpecifier::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB3::Type' (aka 'int')}}
1280// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
1281#endif
1282
1283#if defined(FIRST)
1284struct TA4 { using Type = int; };
1285struct S4 {
1286 TA4::Type x;
1287};
1288# elif defined(SECOND)
1289struct TB4 { using Type = int; };
1290struct S4 {
1291 TB4::Type x;
1292};
1293#else
1294S4 s4;
1295// expected-error@second.h:* {{'NestedNamespaceSpecifier::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'TB4::Type' (aka 'int')}}
1296// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
1297#endif
1298
1299#if defined(FIRST)
1300struct T5 { using Type = int; };
1301struct S5 {
1302 T5::Type x;
1303};
1304# elif defined(SECOND)
1305namespace T5 { using Type = int; };
1306struct S5 {
1307 T5::Type x;
1308};
1309#else
1310S5 s5;
1311// expected-error@second.h:* {{'NestedNamespaceSpecifier::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'T5::Type' (aka 'int')}}
1312// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
1313#endif
1314
1315#if defined(FIRST)
1316namespace N6 {using I = int;}
1317struct S6 {
1318 NestedNamespaceSpecifier::N6::I x;
1319};
1320# elif defined(SECOND)
1321using I = int;
1322struct S6 {
1323 ::NestedNamespaceSpecifier::I x;
1324};
1325#else
1326S6 s6;
1327// expected-error@second.h:* {{'NestedNamespaceSpecifier::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '::NestedNamespaceSpecifier::I' (aka 'int')}}
1328// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
1329#endif
1330
1331#if defined(FIRST)
1332template <class T, class U>
1333class S7 {
1334 typename T::type *x = {};
1335 int z = x->T::foo();
1336};
1337#elif defined(SECOND)
1338template <class T, class U>
1339class S7 {
1340 typename T::type *x = {};
1341 int z = x->U::foo();
1342};
1343#else
1344template <class T, class U>
1345using U7 = S7<T, U>;
1346// expected-error@second.h:* {{'NestedNamespaceSpecifier::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'z' with an initializer}}
1347// expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}}
1348#endif
1349
1350#if defined(FIRST)
1351template <class T>
1352class S8 {
1353 int x = T::template X<int>::value;
1354};
1355#elif defined(SECOND)
1356template <class T>
1357class S8 {
1358 int x = T::template Y<int>::value;
1359};
1360#else
1361template <class T>
1362using U8 = S8<T>;
1363// expected-error@second.h:* {{'NestedNamespaceSpecifier::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}}
1364// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
1365#endif
1366
1367#if defined(FIRST)
1368namespace N9 { using I = int; }
1369namespace O9 = N9;
1370struct S9 {
1371 O9::I x;
1372};
1373#elif defined(SECOND)
1374namespace N9 { using I = int; }
1375namespace P9 = N9;
1376struct S9 {
1377 P9::I x;
1378};
1379#else
1380S9 s9;
1381// expected-error@second.h:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}}
1382// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
1383#endif
Richard Trieu96b41642017-07-01 02:00:05 +00001384
1385namespace N10 {
1386#if defined(FIRST)
1387inline namespace A { struct X {}; }
1388struct S10 {
1389 A::X x;
1390};
1391#elif defined(SECOND)
1392inline namespace B { struct X {}; }
1393struct S10 {
1394 B::X x;
1395};
1396#else
1397S10 s10;
1398// expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
1399// expected-note@first.h:* {{declaration of 'x' does not match}}
1400#endif
1401}
Richard Trieu73cf9242017-11-04 01:20:50 +00001402
1403#define DECLS \
1404 NS1::Type a; \
1405 NS1::NS2::Type b; \
1406 NS1::S c; \
1407 NS3::Type d;
1408
1409#if defined(FIRST) || defined(SECOND)
1410namespace NS1 {
1411 using Type = int;
1412 namespace NS2 {
1413 using Type = double;
1414 }
1415 struct S {};
Richard Trieuce81b192017-05-17 03:23:35 +00001416}
Richard Trieu73cf9242017-11-04 01:20:50 +00001417namespace NS3 = NS1;
1418#endif
1419
1420#if defined(FIRST) || defined(SECOND)
1421struct Valid1 {
1422 DECLS
1423};
1424#else
1425Valid1 v1;
1426#endif
1427
1428#if defined(FIRST) || defined(SECOND)
1429struct Invalid1 {
1430 DECLS
1431 ACCESS
1432};
1433#else
1434Invalid1 i1;
1435// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1436// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1437#endif
1438#undef DECLS
1439
1440#define DECLS \
1441 typename T::type *x = {}; \
1442 int y = x->T::foo(); \
1443 int z = U::template X<int>::value;
1444
1445#if defined(FIRST) || defined(SECOND)
1446template <class T, class U>
1447struct Valid2 {
1448 DECLS
1449};
1450#else
1451template <class T, class U>
1452using V2 = Valid2<T, U>;
1453#endif
1454
1455#if defined(FIRST) || defined(SECOND)
1456template <class T, class U>
1457struct Invalid2 {
1458 DECLS
1459 ACCESS
1460};
1461#else
1462template <class T, class U>
1463using I2 = Invalid2<T, U>;
1464// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1465// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1466#endif
1467#undef DECLS
1468} // namespace NestedNamespaceSpecifier
Richard Trieuce81b192017-05-17 03:23:35 +00001469
Richard Trieu96b49622017-05-31 00:31:58 +00001470namespace TemplateSpecializationType {
1471#if defined(FIRST)
1472template <class T1> struct U1 {};
1473struct S1 {
1474 U1<int> u;
1475};
1476#elif defined(SECOND)
1477template <class T1, class T2> struct U1 {};
1478struct S1 {
1479 U1<int, int> u;
1480};
1481#else
1482S1 s1;
1483// expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}}
1484// expected-note@second.h:* {{declaration of 'u' does not match}}
1485#endif
1486
1487#if defined(FIRST)
1488template <class T1> struct U2 {};
1489struct S2 {
1490 U2<int> u;
1491};
1492#elif defined(SECOND)
1493template <class T1> struct V1 {};
1494struct S2 {
1495 V1<int> u;
1496};
1497#else
1498S2 s2;
1499// expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}}
1500// expected-note@second.h:* {{declaration of 'u' does not match}}
1501#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001502
1503#define DECLS \
1504 OneTemplateArg<int> x; \
1505 OneTemplateArg<double> y; \
1506 OneTemplateArg<char *> z; \
1507 TwoTemplateArgs<int, int> a; \
1508 TwoTemplateArgs<double, float> b; \
1509 TwoTemplateArgs<short *, char> c;
1510
1511#if defined(FIRST) || defined(SECOND)
1512template <class T> struct OneTemplateArg {};
1513template <class T, class U> struct TwoTemplateArgs {};
1514#endif
1515
1516#if defined(FIRST) || defined(SECOND)
1517struct Valid1 {
1518DECLS
1519};
1520#else
1521Valid1 v1;
1522#endif
1523
1524#if defined(FIRST) || defined(SECOND)
1525struct Invalid1 {
1526DECLS
1527ACCESS
1528};
1529#else
1530Invalid1 i1;
1531// expected-error@second.h:* {{'TemplateSpecializationType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1532// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1533#endif
1534#undef DECLS
1535} // namespace TemplateSpecializationType
Richard Trieu96b49622017-05-31 00:31:58 +00001536
Richard Trieu3b261bb72017-06-13 22:21:18 +00001537namespace TemplateArgument {
1538#if defined(FIRST)
1539template <class> struct U1{};
1540struct S1 {
1541 U1<int> x;
1542};
1543#elif defined(SECOND)
1544template <int> struct U1{};
1545struct S1 {
1546 U1<1> x;
1547};
1548#else
1549S1 s1;
1550// expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
1551// expected-note@second.h:* {{declaration of 'x' does not match}}
1552#endif
Richard Trieu1dcb4052017-06-14 01:28:00 +00001553
1554#if defined(FIRST)
1555template <int> struct U2{};
1556struct S2 {
1557 using T = U2<2>;
1558};
1559#elif defined(SECOND)
1560template <int> struct U2{};
1561struct S2 {
1562 using T = U2<(2)>;
1563};
1564#else
1565S2 s2;
1566// expected-error@second.h:* {{'TemplateArgument::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U2<(2)>'}}
1567// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}}
1568#endif
1569
1570#if defined(FIRST)
1571template <int> struct U3{};
1572struct S3 {
1573 using T = U3<2>;
1574};
1575#elif defined(SECOND)
1576template <int> struct U3{};
1577struct S3 {
1578 using T = U3<1 + 1>;
1579};
1580#else
1581S3 s3;
1582// expected-error@second.h:* {{'TemplateArgument::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias 'T' with underlying type 'U3<1 + 1>'}}
1583// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}}
1584#endif
1585
Richard Trieuee132d62017-06-14 03:17:26 +00001586#if defined(FIRST)
1587template<class> struct T4a {};
1588template <template <class> class T> struct U4 {};
1589struct S4 {
1590 U4<T4a> x;
1591};
1592#elif defined(SECOND)
1593template<class> struct T4b {};
1594template <template <class> class T> struct U4 {};
1595struct S4 {
1596 U4<T4b> x;
1597};
1598#else
1599S4 s4;
1600// expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}}
1601// expected-note@second.h:* {{declaration of 'x' does not match}}
1602#endif
Richard Trieu8844c522017-06-30 22:40:33 +00001603
1604#if defined(FIRST)
1605template <class T> struct U5 {};
1606struct S5 {
1607 U5<int> x;
1608};
1609#elif defined(SECOND)
1610template <class T> struct U5 {};
1611struct S5 {
1612 U5<short> x;
1613};
1614#else
1615S5 s5;
1616// expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}}
1617// expected-note@second.h:* {{declaration of 'x' does not match}}
1618#endif
1619
1620#if defined(FIRST)
1621template <class T> struct U6 {};
1622struct S6 {
1623 U6<int> x;
1624 U6<short> y;
1625};
1626#elif defined(SECOND)
1627template <class T> struct U6 {};
1628struct S6 {
1629 U6<short> y;
1630 U6<int> x;
1631};
1632#else
1633S6 s6;
1634// expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
1635// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
1636#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001637
Richard Trieu7282d322018-04-25 00:31:15 +00001638#if defined(FIRST)
1639struct S7 {
1640 template<int> void run() {}
1641 template<> void run<1>() {}
1642};
1643#elif defined(SECOND)
1644struct S7 {
1645 template<int> void run() {}
1646 void run() {}
1647};
1648#else
1649S7 s7;
1650// 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}}
1651// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with template arguments}}
1652#endif
1653
1654#if defined(FIRST)
1655struct S8 {
1656 static int a, b;
1657 template<int&> void run() {}
1658 template<int&, int&> void run() {}
1659 template<> void run<a>() {}
1660};
1661#elif defined(SECOND)
1662struct S8 {
1663 static int a, b;
1664 template<int&> void run() {}
1665 template<int&, int&> void run() {}
1666 template<> void run<a, b>() {}
1667};
1668#else
1669S8 s8;
1670// 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}}
1671// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 1 template argument}}
1672#endif
1673
1674#if defined(FIRST)
1675struct S9 {
1676 static int a, b;
1677 template<int&> void run() {}
1678 template<> void run<a>() {}
1679};
1680#elif defined(SECOND)
1681struct S9 {
1682 static int a, b;
1683 template<int&> void run() {}
1684 template<> void run<b>() {}
1685};
1686#else
1687S9 s9;
1688// 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}}
1689// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 1st template argument}}
1690#endif
1691
1692#if defined(FIRST)
1693struct S10 {
1694 static int a, b;
1695 template<int, int&...> void run() {}
1696 template<> void run<1, a>() {}
1697};
1698#elif defined(SECOND)
1699struct S10 {
1700 static int a, b;
1701 template<int, int&...> void run() {}
1702 template<> void run<1, b>() {}
1703};
1704#else
1705S10 s10;
1706// 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}}
1707// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 2nd template argument}}
1708#endif
1709
1710#if defined(FIRST)
1711struct S11 {
1712 static int a, b;
1713 template<int, int&...> void run() {}
1714 template<> void run<1, a>() {}
1715};
1716#elif defined(SECOND)
1717struct S11 {
1718 static int a, b;
1719 template<int, int&...> void run() {}
1720 template<> void run<1, a, a>() {}
1721};
1722#else
1723S11 s11;
1724// 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}}
1725// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 2 template arguments}}
1726#endif
1727
Richard Trieu73cf9242017-11-04 01:20:50 +00001728#define DECLS \
1729 OneClass<int> a; \
1730 OneInt<1> b; \
1731 using c = OneClass<float>; \
1732 using d = OneInt<2>; \
1733 using e = OneInt<2 + 2>; \
1734 OneTemplateClass<OneClass> f; \
Richard Trieu7282d322018-04-25 00:31:15 +00001735 OneTemplateInt<OneInt> g; \
1736 static int i1, i2; \
1737 template <int &> \
1738 void Function() {} \
1739 template <int &, int &> \
1740 void Function() {} \
1741 template <> \
1742 void Function<i1>() {} \
1743 template <> \
1744 void Function<i2>() {} \
1745 template <> \
1746 void Function<i1, i2>() {} \
1747 template <> \
1748 void Function<i2, i1>() {}
Richard Trieu73cf9242017-11-04 01:20:50 +00001749
1750#if defined(FIRST) || defined(SECOND)
1751template <class> struct OneClass{};
1752template <int> struct OneInt{};
1753template <template <class> class> struct OneTemplateClass{};
1754template <template <int> class> struct OneTemplateInt{};
1755#endif
1756
1757#if defined(FIRST) || defined(SECOND)
1758struct Valid1 {
1759DECLS
1760};
1761#else
1762Valid1 v1;
1763#endif
1764
1765#if defined(FIRST) || defined(SECOND)
1766struct Invalid1 {
1767DECLS
1768ACCESS
1769};
1770#else
1771Invalid1 i1;
1772// expected-error@second.h:* {{'TemplateArgument::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1773// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1774#endif
1775#undef DECLS
1776} // namespace TemplateArgument
Richard Trieuee132d62017-06-14 03:17:26 +00001777
Richard Trieud9201d02017-06-15 01:35:06 +00001778namespace TemplateTypeParmType {
1779#if defined(FIRST)
1780template <class T1, class T2>
1781struct S1 {
1782 T1 x;
1783};
1784#elif defined(SECOND)
1785template <class T1, class T2>
1786struct S1 {
1787 T2 x;
1788};
1789#else
1790using TemplateTypeParmType::S1;
1791// expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}}
1792// expected-note@second.h:* {{declaration of 'x' does not match}}
1793#endif
1794
1795#if defined(FIRST)
1796template <int ...Ts>
1797struct U2 {};
1798template <int T, int U>
1799class S2 {
1800 typedef U2<U, T> type;
1801 type x;
1802};
1803#elif defined(SECOND)
1804template <int ...Ts>
1805struct U2 {};
1806template <int T, int U>
1807class S2 {
1808 typedef U2<T, U> type;
1809 type x;
1810};
1811#else
1812using TemplateTypeParmType::S2;
1813// expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
1814// expected-note@second.h:* {{declaration of 'x' does not match}}
1815// expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
1816// expected-note@second.h:* {{declaration of 'type' does not match}}
1817#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001818
1819#define DECLS \
1820 T t; \
1821 U u; \
1822 ParameterPack<T> a; \
1823 ParameterPack<T, U> b; \
1824 ParameterPack<U> c; \
1825 ParameterPack<U, T> d;
1826
1827#if defined(FIRST) || defined(SECOND)
1828template <class ...Ts> struct ParameterPack {};
1829#endif
1830
1831#if defined(FIRST) || defined(SECOND)
1832template <class T, class U>
1833struct Valid1 {
1834 DECLS
1835};
1836#else
1837using TemplateTypeParmType::Valid1;
1838#endif
1839
1840#if defined(FIRST) || defined(SECOND)
1841template <class T, class U>
1842struct Invalid1 {
1843 DECLS
1844 ACCESS
1845};
1846#else
1847using TemplateTypeParmType::Invalid1;
1848// expected-error@second.h:* {{'TemplateTypeParmType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1849// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1850#endif
1851#undef DECLS
1852} // namespace TemplateTypeParmType
Richard Trieu3b261bb72017-06-13 22:21:18 +00001853
Richard Trieu6e13ff32017-06-16 02:44:29 +00001854namespace VarDecl {
1855#if defined(FIRST)
1856struct S1 {
1857 static int x;
1858 static int y;
1859};
1860#elif defined(SECOND)
1861struct S1 {
1862 static int y;
1863 static int x;
1864};
1865#else
1866S1 s1;
1867// 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'}}
1868// expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}}
1869#endif
1870
1871#if defined(FIRST)
1872struct S2 {
1873 static int x;
1874};
1875#elif defined(SECOND)
1876using I = int;
1877struct S2 {
1878 static I x;
1879};
1880#else
1881S2 s2;
1882// 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')}}
1883// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}}
1884#endif
1885
1886#if defined(FIRST)
1887struct S3 {
1888 static const int x = 1;
1889};
1890#elif defined(SECOND)
1891struct S3 {
1892 static const int x;
1893};
1894#else
1895S3 s3;
1896// 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}}
1897// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}}
1898#endif
1899
1900#if defined(FIRST)
1901struct S4 {
1902 static const int x = 1;
1903};
1904#elif defined(SECOND)
1905struct S4 {
1906 static const int x = 2;
1907};
1908#else
1909S4 s4;
1910// 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}}
1911// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}}
1912#endif
1913
1914#if defined(FIRST)
1915struct S5 {
1916 static const int x = 1;
1917};
1918#elif defined(SECOND)
1919struct S5 {
1920 static constexpr int x = 1;
1921};
1922#else
1923S5 s5;
1924// 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}}
1925// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}}
1926#endif
1927
1928#if defined(FIRST)
1929struct S6 {
1930 static const int x = 1;
1931};
1932#elif defined(SECOND)
1933struct S6 {
1934 static const int y = 1;
1935};
1936#else
1937S6 s6;
1938// expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}}
1939// expected-note@second.h:* {{definition has no member 'x'}}
1940#endif
1941
1942#if defined(FIRST)
1943struct S7 {
1944 static const int x = 1;
1945};
1946#elif defined(SECOND)
1947struct S7 {
1948 static const unsigned x = 1;
1949};
1950#else
1951S7 s7;
1952// expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}}
1953// expected-note@second.h:* {{declaration of 'x' does not match}}
1954#endif
1955
1956#if defined(FIRST)
1957struct S8 {
1958public:
1959 static const int x = 1;
1960};
1961#elif defined(SECOND)
1962struct S8 {
1963 static const int x = 1;
1964public:
1965};
1966#else
1967S8 s8;
1968// expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}}
1969// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1970#endif
1971
1972#if defined(FIRST)
1973struct S9 {
1974 static const int x = 1;
1975};
1976#elif defined(SECOND)
1977struct S9 {
1978 static int x;
1979};
1980#else
1981S9 s9;
1982// expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}}
1983// expected-note@second.h:* {{declaration of 'x' does not match}}
1984#endif
1985
Richard Trieu73cf9242017-11-04 01:20:50 +00001986#define DECLS \
1987 static int a; \
1988 static I b; \
1989 static const int c = 1; \
1990 static constexpr int d = 5;
1991
1992#if defined(FIRST) || defined(SECOND)
1993using I = int;
Richard Trieu6e13ff32017-06-16 02:44:29 +00001994#endif
1995
Richard Trieu73cf9242017-11-04 01:20:50 +00001996#if defined(FIRST) || defined(SECOND)
1997struct Valid1 {
1998 DECLS
Richard Trieu6e13ff32017-06-16 02:44:29 +00001999};
Richard Trieu6e13ff32017-06-16 02:44:29 +00002000#else
Richard Trieu73cf9242017-11-04 01:20:50 +00002001Valid1 v1;
Richard Trieu6e13ff32017-06-16 02:44:29 +00002002#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002003
2004#if defined(FIRST) || defined(SECOND)
2005struct Invalid1 {
2006 DECLS
2007 ACCESS
2008};
2009#else
2010Invalid1 i1;
2011// expected-error@second.h:* {{'VarDecl::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2012// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2013#endif
2014#undef DECLS
2015} // namespace VarDecl
Richard Trieu6e13ff32017-06-16 02:44:29 +00002016
Richard Trieuac6a1b62017-07-08 02:04:42 +00002017namespace Friend {
2018#if defined(FIRST)
2019struct T1 {};
2020struct S1 {
2021 friend class T1;
2022};
2023#elif defined(SECOND)
2024struct T1 {};
2025struct S1 {
2026 friend T1;
2027};
2028#else
2029S1 s1;
2030// expected-error@second.h:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T1'}}
2031// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T1'}}
2032#endif
2033
2034#if defined(FIRST)
2035struct T2 {};
2036struct S2 {
2037 friend class T2;
2038};
2039#elif defined(SECOND)
2040struct T2 {};
2041struct S2 {
2042 friend struct T2;
2043};
2044#else
2045S2 s2;
2046// expected-error@second.h:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}}
2047// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T2'}}
2048#endif
2049
2050#if defined(FIRST)
2051struct T3 {};
2052struct S3 {
2053 friend const T3;
2054};
2055#elif defined(SECOND)
2056struct T3 {};
2057struct S3 {
2058 friend T3;
2059};
2060#else
2061S3 s3;
2062// expected-error@second.h:* {{'Friend::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T3'}}
2063// expected-note@first.h:* {{but in 'FirstModule' found friend 'const Friend::T3'}}
2064#endif
2065
2066#if defined(FIRST)
2067struct T4 {};
2068struct S4 {
2069 friend T4;
2070};
2071#elif defined(SECOND)
2072struct S4 {
2073 friend void T4();
2074};
2075#else
2076S4 s4;
2077// expected-error@second.h:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}}
2078// expected-note@first.h:* {{but in 'FirstModule' found friend class}}
2079#endif
2080
2081#if defined(FIRST)
2082struct S5 {
2083 friend void T5a();
2084};
2085#elif defined(SECOND)
2086struct S5 {
2087 friend void T5b();
2088};
2089#else
2090S5 s5;
2091// expected-error@second.h:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}}
2092// expected-note@first.h:* {{but in 'FirstModule' found friend function 'T5a'}}
2093#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002094
2095#define DECLS \
2096 friend class FriendA; \
2097 friend struct FriendB; \
2098 friend FriendC; \
2099 friend const FriendD; \
2100 friend void Function();
2101
2102#if defined(FIRST) || defined(SECOND)
2103class FriendA {};
2104class FriendB {};
2105class FriendC {};
2106class FriendD {};
2107#endif
2108
2109#if defined(FIRST) || defined(SECOND)
2110struct Valid1 {
2111 DECLS
2112};
2113#else
2114Valid1 v1;
2115#endif
2116
2117#if defined(FIRST) || defined(SECOND)
2118struct Invalid1 {
2119 DECLS
2120 ACCESS
2121};
2122#else
2123Invalid1 i1;
2124// expected-error@second.h:* {{'Friend::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2125// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2126#endif
2127#undef DECLS
2128} // namespace Friend
Richard Trieu498117b2017-08-23 02:43:59 +00002129
2130namespace TemplateParameters {
2131#if defined(FIRST)
2132template <class A>
2133struct S1 {};
2134#elif defined(SECOND)
2135template <class B>
2136struct S1 {};
2137#else
2138using TemplateParameters::S1;
2139// expected-error@second.h:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}}
2140// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2141#endif
2142
2143#if defined(FIRST)
2144template <class A = double>
2145struct S2 {};
2146#elif defined(SECOND)
2147template <class A = int>
2148struct S2 {};
2149#else
2150using TemplateParameters::S2;
2151// 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}}
2152// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2153#endif
2154
2155#if defined(FIRST)
2156template <class A = int>
2157struct S3 {};
2158#elif defined(SECOND)
2159template <class A>
2160struct S3 {};
2161#else
2162using TemplateParameters::S3;
2163// 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}}
2164// expected-note@first.h:* {{but in 'FirstModule' found template parameter with default argument}}
2165#endif
2166
2167#if defined(FIRST)
2168template <int A>
2169struct S4 {};
2170#elif defined(SECOND)
2171template <int A = 2>
2172struct S4 {};
2173#else
2174using TemplateParameters::S4;
2175// 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}}
2176// expected-note@first.h:* {{but in 'FirstModule' found template parameter with no default argument}}
2177#endif
2178
2179#if defined(FIRST)
2180template <int> class S5_first {};
2181template <template<int> class A = S5_first>
2182struct S5 {};
2183#elif defined(SECOND)
2184template <int> class S5_second {};
2185template <template<int> class A = S5_second>
2186struct S5 {};
2187#else
2188using TemplateParameters::S5;
2189// 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}}
2190// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2191#endif
2192
2193#if defined(FIRST)
2194template <class A>
2195struct S6 {};
2196#elif defined(SECOND)
2197template <class>
2198struct S6 {};
2199#else
2200using TemplateParameters::S6;
2201// expected-error@second.h:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}}
2202// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2203#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002204
2205#define DECLS
2206
2207#if defined(FIRST) || defined(SECOND)
2208template <class> class DefaultArg;
2209#endif
2210
2211#if defined(FIRST) || defined(SECOND)
2212template <int, class, template <class> class,
2213 int A, class B, template <int> class C,
2214 int D = 1, class E = int, template <class F> class = DefaultArg>
2215struct Valid1 {
2216 DECLS
2217};
2218#else
2219using TemplateParameters::Valid1;
2220#endif
2221
2222#if defined(FIRST) || defined(SECOND)
2223template <int, class, template <class> class,
2224 int A, class B, template <int> class C,
2225 int D = 1, class E = int, template <class F> class = DefaultArg>
2226struct Invalid1 {
2227 DECLS
2228 ACCESS
2229};
2230#else
2231using TemplateParameters::Invalid1;
2232// expected-error@second.h:* {{'TemplateParameters::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2233// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2234#endif
2235#undef DECLS
Richard Trieu498117b2017-08-23 02:43:59 +00002236} // namespace TemplateParameters
2237
Richard Trieue13eabe2017-09-30 02:19:17 +00002238namespace BaseClass {
2239#if defined(FIRST)
2240struct B1 {};
2241struct S1 : B1 {};
2242#elif defined(SECOND)
2243struct S1 {};
2244#else
2245S1 s1;
2246// expected-error@second.h:* {{'BaseClass::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 base classes}}
2247// expected-note@first.h:* {{but in 'FirstModule' found 1 base class}}
2248#endif
2249
2250#if defined(FIRST)
2251struct S2 {};
2252#elif defined(SECOND)
2253struct B2 {};
2254struct S2 : virtual B2 {};
2255#else
2256S2 s2;
2257// expected-error@second.h:* {{'BaseClass::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 base class}}
2258// expected-note@first.h:* {{but in 'FirstModule' found 0 base classes}}
2259#endif
2260
2261#if defined(FIRST)
2262struct B3a {};
2263struct S3 : B3a {};
2264#elif defined(SECOND)
2265struct B3b {};
2266struct S3 : virtual B3b {};
2267#else
2268S3 s3;
2269// expected-error@second.h:* {{'BaseClass::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2270// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2271#endif
2272
2273#if defined(FIRST)
2274struct B4a {};
2275struct S4 : B4a {};
2276#elif defined(SECOND)
2277struct B4b {};
2278struct S4 : B4b {};
2279#else
2280S4 s4;
2281// 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'}}
2282// expected-note@first.h:* {{but in 'FirstModule' found 1st base class with different type 'BaseClass::B4a'}}
2283#endif
2284
2285#if defined(FIRST)
2286struct B5a {};
2287struct S5 : virtual B5a {};
2288#elif defined(SECOND)
2289struct B5a {};
2290struct S5 : B5a {};
2291#else
2292S5 s5;
2293// expected-error@second.h:* {{'BaseClass::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 virtual base classes}}
2294// expected-note@first.h:* {{but in 'FirstModule' found 1 virtual base class}}
2295#endif
2296
2297#if defined(FIRST)
2298struct B6a {};
2299struct S6 : B6a {};
2300#elif defined(SECOND)
2301struct B6a {};
2302struct S6 : virtual B6a {};
2303#else
2304S6 s6;
2305// expected-error@second.h:* {{'BaseClass::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2306// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2307#endif
2308
2309#if defined(FIRST)
2310struct B7a {};
2311struct S7 : protected B7a {};
2312#elif defined(SECOND)
2313struct B7a {};
2314struct S7 : B7a {};
2315#else
2316S7 s7;
2317// 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}}
2318// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B7a' with protected access specifier}}
2319#endif
2320
2321#if defined(FIRST)
2322struct B8a {};
2323struct S8 : public B8a {};
2324#elif defined(SECOND)
2325struct B8a {};
2326struct S8 : private B8a {};
2327#else
2328S8 s8;
2329// 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}}
2330// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B8a' with public access specifier}}
2331#endif
2332
2333#if defined(FIRST)
2334struct B9a {};
2335struct S9 : private B9a {};
2336#elif defined(SECOND)
2337struct B9a {};
2338struct S9 : public B9a {};
2339#else
2340S9 s9;
2341// 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}}
2342// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B9a' with private access specifier}}
2343#endif
2344
2345#if defined(FIRST)
2346struct B10a {};
2347struct S10 : B10a {};
2348#elif defined(SECOND)
2349struct B10a {};
2350struct S10 : protected B10a {};
2351#else
2352S10 s10;
2353// 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}}
2354// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B10a' with no access specifier}}
2355#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002356
2357#define DECLS
2358
2359#if defined(FIRST) || defined(SECOND)
2360struct Base1 {};
2361struct Base2 {};
2362struct Base3 {};
2363struct Base4 {};
2364struct Base5 {};
2365#endif
2366
2367#if defined(FIRST) || defined(SECOND)
2368struct Valid1 :
2369 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2370
2371 DECLS
2372};
2373#else
2374Valid1 v1;
2375#endif
2376
2377#if defined(FIRST) || defined(SECOND)
2378struct Invalid1 :
2379 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2380
2381 DECLS
2382 ACCESS
2383};
2384#else
2385Invalid1 i1;
2386// expected-error@second.h:* {{'BaseClass::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2387// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2388#endif
2389#undef DECLS
Richard Trieue13eabe2017-09-30 02:19:17 +00002390} // namespace BaseClass
2391
Richard Trieu15970af2018-04-13 22:34:43 +00002392namespace PointersAndReferences {
2393#if defined(FIRST) || defined(SECOND)
2394template<typename> struct Wrapper{};
2395#endif
2396
2397#if defined(FIRST)
2398struct S1 {
2399 Wrapper<int*> x;
2400};
2401#elif defined(SECOND)
2402struct S1 {
2403 Wrapper<float*> x;
2404};
2405#else
2406S1 s1;
2407// expected-error@first.h:* {{PointersAndReferences::S1::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S1' in module 'SecondModule'}}
2408// expected-note@second.h:* {{declaration of 'x' does not match}}
2409#endif
2410
2411#if defined(FIRST)
2412struct S2 {
2413 Wrapper<int &&> x;
2414};
2415#elif defined(SECOND)
2416struct S2 {
2417 Wrapper<float &&> x;
2418};
2419#else
2420S2 s2;
2421// expected-error@first.h:* {{PointersAndReferences::S2::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S2' in module 'SecondModule'}}
2422// expected-note@second.h:* {{declaration of 'x' does not match}}
2423#endif
2424
2425#if defined(FIRST)
2426struct S3 {
2427 Wrapper<int *> x;
2428};
2429#elif defined(SECOND)
2430struct S3 {
2431 Wrapper<float *> x;
2432};
2433#else
2434S3 s3;
2435// expected-error@first.h:* {{PointersAndReferences::S3::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S3' in module 'SecondModule'}}
2436// expected-note@second.h:* {{declaration of 'x' does not match}}
2437#endif
2438
2439#if defined(FIRST)
2440struct S4 {
2441 Wrapper<int &> x;
2442};
2443#elif defined(SECOND)
2444struct S4 {
2445 Wrapper<float &> x;
2446};
2447#else
2448S4 s4;
2449// expected-error@first.h:* {{PointersAndReferences::S4::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S4' in module 'SecondModule'}}
2450// expected-note@second.h:* {{declaration of 'x' does not match}}
2451#endif
2452
2453#if defined(FIRST)
2454struct S5 {
2455 Wrapper<S5 *> x;
2456};
2457#elif defined(SECOND)
2458struct S5 {
2459 Wrapper<const S5 *> x;
2460};
2461#else
2462S5 s5;
2463// expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 'SecondModule' is not present in definition of 'PointersAndReferences::S5' in module 'FirstModule'}}
2464// expected-note@first.h:* {{declaration of 'x' does not match}}
2465#endif
2466
2467#if defined(FIRST)
2468struct S6 {
2469 Wrapper<int &> x;
2470};
2471#elif defined(SECOND)
2472struct S6 {
2473 Wrapper<const int &> x;
2474};
2475#else
2476S6 s6;
2477// expected-error@first.h:* {{PointersAndReferences::S6::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S6' in module 'SecondModule'}}
2478// expected-note@second.h:* {{declaration of 'x' does not match}}
2479#endif
2480
2481#define DECLS \
2482 Wrapper<int *> x1; \
2483 Wrapper<float *> x2; \
2484 Wrapper<const float *> x3; \
2485 Wrapper<int &> x4; \
2486 Wrapper<int &&> x5; \
2487 Wrapper<const int &> x6; \
2488 Wrapper<S1 *> x7; \
2489 Wrapper<S1 &> x8; \
2490 Wrapper<S1 &&> x9;
2491
2492#if defined(FIRST) || defined(SECOND)
2493struct Valid1 {
2494 DECLS
2495};
2496#else
2497Valid1 v1;
2498#endif
2499
2500#if defined(FIRST) || defined(SECOND)
2501struct Invalid1 {
2502 DECLS
2503 ACCESS
2504};
2505#else
2506Invalid1 i1;
2507// expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2508// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2509#endif
2510#undef DECLS
2511} // namespace PointersAndReferences
2512
Richard Trieu9359e8f2018-05-30 01:12:26 +00002513namespace FunctionTemplate {
2514#if defined(FIRST)
2515struct S1 {
2516 template <int, int> void foo();
2517};
2518#elif defined(SECOND)
2519struct S1 {
2520 template <int> void foo();
2521};
2522#else
2523S1 s1;
2524// expected-error@first.h:* {{'FunctionTemplate::S1::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S1' in module 'SecondModule'}}
2525// expected-note@second.h:* {{declaration of 'foo' does not match}}
2526#endif
2527
2528#if defined(FIRST)
2529struct S2 {
2530 template <char> void foo();
2531};
2532#elif defined(SECOND)
2533struct S2 {
2534 template <int> void foo();
2535};
2536#else
2537S2 s2;
2538// expected-error@first.h:* {{'FunctionTemplate::S2::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S2' in module 'SecondModule'}}
2539// expected-note@second.h:* {{declaration of 'foo' does not match}}
2540#endif
2541
2542#if defined(FIRST)
2543struct S3 {
2544 template <int x> void foo();
2545};
2546#elif defined(SECOND)
2547struct S3 {
2548 template <int y> void foo();
2549};
2550#else
2551S3 s3;
2552// 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'}}
2553// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2554#endif
2555
2556#if defined(FIRST)
2557struct S4 {
2558 template <int x> void foo();
2559};
2560#elif defined(SECOND)
2561struct S4 {
2562 template <int x> void bar();
2563};
2564#else
2565S4 s4;
2566// expected-error@first.h:* {{'FunctionTemplate::S4::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S4' in module 'SecondModule'}}
2567// expected-note@second.h:* {{definition has no member 'foo'}}
2568#endif
2569
2570#if defined(FIRST)
2571struct S5 {
2572 template <int x> void foo();
2573};
2574#elif defined(SECOND)
2575struct S5 {
2576 public:
2577 template <int x> void foo();
2578};
2579#else
2580S5 s5;
2581// expected-error@second.h:* {{'FunctionTemplate::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2582// expected-note@first.h:* {{but in 'FirstModule' found function template}}
2583#endif
2584
2585#if defined(FIRST)
2586struct S6 {
2587 template <typename x = int> void foo();
2588};
2589#elif defined(SECOND)
2590struct S6 {
2591 template <typename x> void foo();
2592};
2593#else
2594S6 s6;
2595// 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}}
2596// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2597#endif
2598
2599#if defined(FIRST)
2600struct S7 {
2601 template <typename x = void> void foo();
2602};
2603#elif defined(SECOND)
2604struct S7 {
2605 template <typename x = int> void foo();
2606};
2607#else
2608S7 s7;
2609// 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'}}
2610// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'void'}}
2611#endif
2612
2613#if defined(FIRST)
2614template <int>
2615struct U8 {};
2616struct S8 {
2617 template <template<int> class x = U8> void foo();
2618};
2619#elif defined(SECOND)
2620template <int>
2621struct T8 {};
2622struct S8{
2623 template <template<int> class x = T8> void foo();
2624};
2625#else
2626S8 s8;
2627// 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'}}
2628// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'U8'}}
2629#endif
2630
2631#if defined(FIRST)
2632template <int>
2633struct U9 {};
2634struct S9 { S9();
2635 template <template<int> class x = U9> void foo();
2636};
2637#elif defined(SECOND)
2638struct S9 { S9();
2639 template <template<int> class x> void foo();
2640};
2641#else
2642S9 s9;
2643// 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}}
2644// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2645#endif
2646
2647#if defined(FIRST)
2648struct S10 {
2649 template <template<int> class x> void foo();
2650 template <template<typename> class x> void foo();
2651};
2652#elif defined(SECOND)
2653struct S10 {
2654 template <template<typename> class x> void foo();
2655 template <template<int> class x> void foo();
2656};
2657#else
2658S10 s10;
2659// 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}}
2660// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
2661#endif
2662
2663#if defined(FIRST)
2664struct S11 {
2665 template <template<int> class x> void foo();
2666};
2667#elif defined(SECOND)
2668struct S11 {
2669 template <template<int> class> void foo();
2670};
2671#else
2672S11 s11;
2673// 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}}
2674// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2675#endif
2676
2677#if defined(FIRST)
2678struct S12 {
2679 template <class> void foo();
2680 template <class, class> void foo();
2681};
2682#elif defined(SECOND)
2683struct S12 {
2684 template <class, class> void foo();
2685 template <class> void foo();
2686};
2687#else
2688S12 s12;
2689// 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}}
2690// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1 template parameter}}
2691#endif
2692
2693#if defined(FIRST)
2694struct S13 {
2695 template <class = int> void foo();
2696};
2697#elif defined(SECOND)
2698struct S13 {
2699 template <class = void> void foo();
2700};
2701#else
2702S13 s13;
2703// 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'}}
2704// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'int'}}
2705#endif
2706
2707#if defined(FIRST)
2708struct S14 {
2709 template <class = void> void foo();
2710};
2711#elif defined(SECOND)
2712struct S14 {
2713 template <class> void foo();
2714};
2715#else
2716S14 s14;
2717// 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}}
2718// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2719#endif
2720
2721#if defined(FIRST)
2722struct S15 {
2723 template <class> void foo();
2724};
2725#elif defined(SECOND)
2726struct S15 {
2727 template <class = void> void foo();
2728};
2729#else
2730S15 s15;
2731// 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}}
2732// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
2733#endif
2734
2735#if defined(FIRST)
2736struct S16 {
2737 template <short> void foo();
2738};
2739#elif defined(SECOND)
2740struct S16 {
2741 template <short = 1> void foo();
2742};
2743#else
2744S16 s16;
2745// 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}}
2746// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
2747#endif
2748
2749#if defined(FIRST)
2750struct S17 {
2751 template <short = 2> void foo();
2752};
2753#elif defined(SECOND)
2754struct S17 {
2755 template <short = 1 + 1> void foo();
2756};
2757#else
2758S17 s17;
2759// 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}}
2760// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 2}}
2761#endif
2762
2763#if defined(FIRST)
2764struct S18 {
2765 template <short> void foo();
2766 template <int> void foo();
2767};
2768#elif defined(SECOND)
2769struct S18 {
2770 template <int> void foo();
2771 template <short> void foo();
2772};
2773#else
2774S18 s18;
2775// 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}}
2776// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
2777#endif
2778
2779#if defined(FIRST)
2780struct S19 {
2781 template <short> void foo();
2782 template <short...> void foo();
2783};
2784#elif defined(SECOND)
2785struct S19 {
2786 template <short...> void foo();
2787 template <short> void foo();
2788};
2789#else
2790S19 s19;
2791// 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}}
2792// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
2793#endif
2794
2795#if defined(FIRST)
2796struct S20 {
2797 template <class> void foo();
2798 template <class...> void foo();
2799};
2800#elif defined(SECOND)
2801struct S20 {
2802 template <class...> void foo();
2803 template <class> void foo();
2804};
2805#else
2806S20 s20;
2807// 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}}
2808// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
2809#endif
2810
2811#if defined(FIRST)
2812struct S21 {
2813 template <template<class> class...> void foo();
2814 template <template<class> class> void foo();
2815};
2816#elif defined(SECOND)
2817struct S21 {
2818 template <template<class> class> void foo();
2819 template <template<class> class...> void foo();
2820};
2821#else
2822S21 s21;
2823// 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}}
2824// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter being a template parameter pack}}
2825#endif
2826
2827#if defined(FIRST)
2828struct S22 {
2829 template <template<class> class> void foo();
2830 template <class> void foo();
2831 template <int> void foo();
2832};
2833#elif defined(SECOND)
2834struct S22 {
2835 template <class> void foo();
2836 template <int> void foo();
2837 template <template<class> class> void foo();
2838};
2839#else
2840S22 s22;
2841// 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}}
2842// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a template template parameter}}
2843#endif
2844
2845#if defined(FIRST)
2846struct S23 {
2847 template <class> void foo();
2848 template <int> void foo();
2849 template <template<class> class> void foo();
2850};
2851#elif defined(SECOND)
2852struct S23 {
2853 template <int> void foo();
2854 template <template<class> class> void foo();
2855 template <class> void foo();
2856};
2857#else
2858S23 s23;
2859// 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}}
2860// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a type template parameter}}
2861#endif
2862
2863#if defined(FIRST)
2864struct S24 {
2865 template <int> void foo();
2866 template <template<class> class> void foo();
2867 template <class> void foo();
2868};
2869#elif defined(SECOND)
2870struct S24 {
2871 template <template<class> class> void foo();
2872 template <class> void foo();
2873 template <int> void foo();
2874};
2875#else
2876S24 s24;
2877// 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}}
2878// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a non-type template parameter}}
2879#endif
2880
2881#if defined(FIRST)
2882struct S25 {
2883 template <int> void foo();
2884};
2885#elif defined(SECOND)
2886struct S25 {
2887 public:
2888 template <int> void foo();
2889};
2890#else
2891S25 s25;
2892// expected-error@second.h:* {{'FunctionTemplate::S25' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2893// expected-note@first.h:* {{but in 'FirstModule' found function template}}
2894#endif
2895
2896#define DECLS \
2897 template <int> \
2898 void nontype1(); \
2899 template <int x> \
2900 void nontype2(); \
2901 template <int, int> \
2902 void nontype3(); \
2903 template <int x = 5> \
2904 void nontype4(); \
2905 template <int... x> \
2906 void nontype5(); \
2907 \
2908 template <class> \
2909 void type1(); \
2910 template <class x> \
2911 void type2(); \
2912 template <class, class> \
2913 void type3(); \
2914 template <class x = int> \
2915 void type4(); \
2916 template <class... x> \
2917 void type5(); \
2918 \
2919 template <template <int> class> \
2920 void template1(); \
2921 template <template <int> class x> \
2922 void template2(); \
2923 template <template <int> class, template <int> class> \
2924 void template3(); \
2925 template <template <int> class x = U> \
2926 void template4(); \
2927 template <template <int> class... x> \
2928 void template5();
2929
2930#if defined(FIRST) || defined(SECOND)
2931template<int>
2932struct U {};
2933struct Valid1 {
2934 DECLS
2935};
2936#else
2937Valid1 v1;
2938#endif
2939
2940#if defined(FIRST) || defined(SECOND)
2941struct Invalid1 {
2942 DECLS
2943 ACCESS
2944};
2945#else
2946Invalid1 i1;
2947// expected-error@second.h:* {{'FunctionTemplate::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2948// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2949#endif
2950#undef DECLS
2951}
Richard Trieu73cf9242017-11-04 01:20:50 +00002952
2953// Collection of interesting cases below.
2954
2955// Naive parsing of AST can lead to cycles in processing. Ensure
2956// self-references don't trigger an endless cycles of AST node processing.
2957namespace SelfReference {
2958#if defined(FIRST)
2959template <template <int> class T> class Wrapper {};
2960
2961template <int N> class S {
2962 S(Wrapper<::SelfReference::S> &Ref) {}
2963};
2964
2965struct Xx {
2966 struct Yy {
Richard Trieufe564052017-04-20 02:53:53 +00002967 };
Richard Trieu73cf9242017-11-04 01:20:50 +00002968};
Richard Trieufe564052017-04-20 02:53:53 +00002969
Richard Trieu73cf9242017-11-04 01:20:50 +00002970Xx::Xx::Xx::Yy yy;
Richard Trieue7f7ed22017-02-22 01:11:25 +00002971
Richard Trieu73cf9242017-11-04 01:20:50 +00002972namespace NNS {
2973template <typename> struct Foo;
2974template <template <class> class T = NNS::Foo>
2975struct NestedNamespaceSpecifier {};
Richard Trieue7f7ed22017-02-22 01:11:25 +00002976}
Richard Trieu73cf9242017-11-04 01:20:50 +00002977#endif
2978} // namespace SelfReference
Richard Trieue7f7ed22017-02-22 01:11:25 +00002979
2980namespace FriendFunction {
2981#if defined(FIRST)
2982void F(int = 0);
2983struct S { friend void F(int); };
2984#elif defined(SECOND)
2985void F(int);
2986struct S { friend void F(int); };
2987#else
2988S s;
2989#endif
2990
2991#if defined(FIRST)
2992void G(int = 0);
2993struct T {
2994 friend void G(int);
2995
2996 private:
2997};
2998#elif defined(SECOND)
2999void G(int);
3000struct T {
3001 friend void G(int);
3002
3003 public:
3004};
3005#else
3006T t;
3007// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3008// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3009#endif
3010} // namespace FriendFunction
3011
3012namespace ImplicitDecl {
3013#if defined(FIRST)
3014struct S { };
3015void S_Constructors() {
3016 // Trigger creation of implicit contructors
3017 S foo;
3018 S bar = foo;
3019 S baz(bar);
3020}
3021#elif defined(SECOND)
3022struct S { };
3023#else
3024S s;
3025#endif
3026
3027#if defined(FIRST)
3028struct T {
3029 private:
3030};
3031void T_Constructors() {
3032 // Trigger creation of implicit contructors
3033 T foo;
3034 T bar = foo;
3035 T baz(bar);
3036}
3037#elif defined(SECOND)
3038struct T {
3039 public:
3040};
3041#else
3042T t;
3043// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
3044// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
3045#endif
3046
Richard Trieu73cf9242017-11-04 01:20:50 +00003047} // namespace ImplicitDecl
Richard Trieue7f7ed22017-02-22 01:11:25 +00003048
3049namespace TemplatedClass {
3050#if defined(FIRST)
3051template <class>
3052struct S {};
3053#elif defined(SECOND)
3054template <class>
3055struct S {};
3056#else
3057S<int> s;
3058#endif
3059
3060#if defined(FIRST)
3061template <class>
3062struct T {
3063 private:
3064};
3065#elif defined(SECOND)
3066template <class>
3067struct T {
3068 public:
3069};
3070#else
3071T<int> t;
3072// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3073// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3074#endif
3075} // namespace TemplatedClass
3076
3077namespace TemplateClassWithField {
3078#if defined(FIRST)
3079template <class A>
3080struct S {
3081 A a;
3082};
3083#elif defined(SECOND)
3084template <class A>
3085struct S {
3086 A a;
3087};
3088#else
3089S<int> s;
3090#endif
3091
3092#if defined(FIRST)
3093template <class A>
3094struct T {
3095 A a;
3096
3097 private:
3098};
3099#elif defined(SECOND)
3100template <class A>
3101struct T {
3102 A a;
3103
3104 public:
3105};
3106#else
3107T<int> t;
3108// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3109// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3110#endif
3111} // namespace TemplateClassWithField
3112
3113namespace TemplateClassWithTemplateField {
3114#if defined(FIRST)
3115template <class A>
3116class WrapperS;
3117template <class A>
3118struct S {
3119 WrapperS<A> a;
3120};
3121#elif defined(SECOND)
3122template <class A>
3123class WrapperS;
3124template <class A>
3125struct S {
3126 WrapperS<A> a;
3127};
3128#else
3129template <class A>
3130class WrapperS{};
3131S<int> s;
3132#endif
3133
3134#if defined(FIRST)
3135template <class A>
3136class WrapperT;
3137template <class A>
3138struct T {
3139 WrapperT<A> a;
3140
3141 public:
3142};
3143#elif defined(SECOND)
3144template <class A>
3145class WrapperT;
3146template <class A>
3147struct T {
3148 WrapperT<A> a;
3149
3150 private:
3151};
3152#else
3153template <class A>
3154class WrapperT{};
3155T<int> t;
3156// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3157// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3158#endif
3159} // namespace TemplateClassWithTemplateField
3160
3161namespace EnumWithForwardDeclaration {
3162#if defined(FIRST)
3163enum E : int;
3164struct S {
3165 void get(E) {}
3166};
3167#elif defined(SECOND)
3168enum E : int { A, B };
3169struct S {
3170 void get(E) {}
3171};
3172#else
3173S s;
3174#endif
3175
3176#if defined(FIRST)
3177struct T {
3178 void get(E) {}
3179 public:
3180};
3181#elif defined(SECOND)
3182struct T {
3183 void get(E) {}
3184 private:
3185};
3186#else
3187T t;
3188// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3189// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3190#endif
3191} // namespace EnumWithForwardDeclaration
3192
3193namespace StructWithForwardDeclaration {
3194#if defined(FIRST)
3195struct P {};
3196struct S {
3197 struct P *ptr;
3198};
3199#elif defined(SECOND)
3200struct S {
3201 struct P *ptr;
3202};
3203#else
3204S s;
3205#endif
3206
3207#if defined(FIRST)
3208struct Q {};
3209struct T {
3210 struct Q *ptr;
3211 public:
3212};
3213#elif defined(SECOND)
3214struct T {
3215 struct Q *ptr;
3216 private:
3217};
3218#else
3219T t;
3220// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3221// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3222#endif
3223} // namespace StructWithForwardDeclaration
3224
3225namespace StructWithForwardDeclarationNoDefinition {
3226#if defined(FIRST)
3227struct P;
3228struct S {
3229 struct P *ptr;
3230};
3231#elif defined(SECOND)
3232struct S {
3233 struct P *ptr;
3234};
3235#else
3236S s;
3237#endif
3238
3239#if defined(FIRST)
3240struct Q;
3241struct T {
3242 struct Q *ptr;
3243
3244 public:
3245};
3246#elif defined(SECOND)
3247struct T {
3248 struct Q *ptr;
3249
3250 private:
3251};
3252#else
3253T t;
3254// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3255// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3256#endif
3257} // namespace StructWithForwardDeclarationNoDefinition
3258
Richard Trieufe564052017-04-20 02:53:53 +00003259namespace LateParsedDefaultArgument {
3260#if defined(FIRST)
3261template <typename T>
3262struct S {
3263 struct R {
3264 void foo(T x = 0) {}
3265 };
3266};
3267#elif defined(SECOND)
3268#else
3269void run() {
3270 S<int>::R().foo();
3271}
3272#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003273} // namespace LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00003274
3275namespace LateParsedDefaultArgument {
3276#if defined(FIRST)
3277template <typename alpha> struct Bravo {
3278 void charlie(bool delta = false) {}
3279};
3280typedef Bravo<char> echo;
3281echo foxtrot;
3282
3283Bravo<char> golf;
3284#elif defined(SECOND)
3285#else
3286#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003287} // LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00003288
Richard Trieu157ed942017-04-28 22:03:28 +00003289namespace DifferentParameterNameInTemplate {
3290#if defined(FIRST) || defined(SECOND)
3291template <typename T>
3292struct S {
3293 typedef T Type;
3294
3295 static void Run(const Type *name_one);
3296};
3297
3298template <typename T>
3299void S<T>::Run(const T *name_two) {}
3300
3301template <typename T>
3302struct Foo {
3303 ~Foo() { Handler::Run(nullptr); }
3304 Foo() {}
3305
3306 class Handler : public S<T> {};
3307
3308 void Get(typename Handler::Type *x = nullptr) {}
3309 void Add() { Handler::Run(nullptr); }
3310};
3311#endif
3312
3313#if defined(FIRST)
3314struct Beta;
3315
3316struct Alpha {
3317 Alpha();
3318 void Go() { betas.Get(); }
3319 Foo<Beta> betas;
3320};
3321
3322#elif defined(SECOND)
3323struct Beta {};
3324
3325struct BetaHelper {
3326 void add_Beta() { betas.Add(); }
3327 Foo<Beta> betas;
3328};
3329
3330#else
3331Alpha::Alpha() {}
3332#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003333} // DifferentParameterNameInTemplate
Richard Trieu157ed942017-04-28 22:03:28 +00003334
Richard Trieu02552272017-05-02 23:58:52 +00003335namespace ParameterTest {
3336#if defined(FIRST)
3337class X {};
3338template <typename G>
3339class S {
3340 public:
3341 typedef G Type;
3342 static inline G *Foo(const G *a, int * = nullptr);
3343};
3344
3345template<typename G>
3346G* S<G>::Foo(const G* aaaa, int*) {}
3347#elif defined(SECOND)
3348template <typename G>
3349class S {
3350 public:
3351 typedef G Type;
3352 static inline G *Foo(const G *a, int * = nullptr);
3353};
3354
3355template<typename G>
3356G* S<G>::Foo(const G* asdf, int*) {}
3357#else
3358S<X> s;
3359#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003360} // ParameterTest
Richard Trieu02552272017-05-02 23:58:52 +00003361
Richard Trieub35ef2a2017-05-09 03:24:34 +00003362namespace MultipleTypedefs {
3363#if defined(FIRST)
3364typedef int B1;
3365typedef B1 A1;
3366struct S1 {
3367 A1 x;
3368};
3369#elif defined(SECOND)
3370typedef int A1;
3371struct S1 {
3372 A1 x;
3373};
3374#else
3375S1 s1;
3376#endif
3377
3378#if defined(FIRST)
3379struct T2 { int x; };
3380typedef T2 B2;
3381typedef B2 A2;
3382struct S2 {
3383 T2 x;
3384};
3385#elif defined(SECOND)
3386struct T2 { int x; };
3387typedef T2 A2;
3388struct S2 {
3389 T2 x;
3390};
3391#else
3392S2 s2;
3393#endif
Richard Trieu3e03d3e2017-06-29 22:53:04 +00003394
3395#if defined(FIRST)
3396using A3 = const int;
3397using B3 = volatile A3;
3398struct S3 {
3399 B3 x = 1;
3400};
3401#elif defined(SECOND)
3402using A3 = volatile const int;
3403using B3 = A3;
3404struct S3 {
3405 B3 x = 1;
3406};
3407#else
3408S3 s3;
3409#endif
Richard Trieucaaccee2018-04-12 02:26:49 +00003410
3411#if defined(FIRST)
3412using A4 = int;
3413using B4 = A4;
3414struct S4 {
3415 B4 x;
3416};
3417#elif defined(SECOND)
3418using A4 = int;
3419using B4 = ::MultipleTypedefs::A4;
3420struct S4 {
3421 B4 x;
3422};
3423#else
3424S4 s4;
3425#endif
3426
3427#if defined(FIRST)
3428using A5 = int;
3429using B5 = MultipleTypedefs::A5;
3430struct S5 {
3431 B5 x;
3432};
3433#elif defined(SECOND)
3434using A5 = int;
3435using B5 = ::MultipleTypedefs::A5;
3436struct S5 {
3437 B5 x;
3438};
3439#else
3440S5 s5;
3441#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003442} // MultipleTypedefs
3443
3444namespace DefaultArguments {
3445#if defined(FIRST)
3446template <typename T>
3447struct S {
3448 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00003449 void foo(T x = 0);
Richard Trieu73cf9242017-11-04 01:20:50 +00003450 };
3451};
3452#elif defined(SECOND)
3453template <typename T>
3454struct S {
3455 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00003456 void foo(T x = 1);
Richard Trieu73cf9242017-11-04 01:20:50 +00003457 };
3458};
3459#else
3460void run() {
3461 S<int>::R().foo();
Richard Trieub35ef2a2017-05-09 03:24:34 +00003462}
Richard Trieu73cf9242017-11-04 01:20:50 +00003463// 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}}
3464// expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}}
3465#endif
3466
3467#if defined(FIRST)
3468template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00003469 void charlie(bool delta = false);
Richard Trieu73cf9242017-11-04 01:20:50 +00003470};
3471typedef Bravo<char> echo;
3472echo foxtrot;
3473#elif defined(SECOND)
3474template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00003475 void charlie(bool delta = (false));
Richard Trieu73cf9242017-11-04 01:20:50 +00003476};
3477typedef Bravo<char> echo;
3478echo foxtrot;
3479#else
3480Bravo<char> golf;
3481// 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}}
3482// expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}}
3483#endif
3484} // namespace DefaultArguments
Richard Trieu02552272017-05-02 23:58:52 +00003485
Richard Trieue6caa262017-12-23 00:41:01 +00003486namespace FunctionDecl {
3487#if defined(FIRST)
3488struct S1 {};
3489S1 s1a;
3490#elif defined(SECOND)
3491struct S1 {};
3492#else
3493S1 s1;
3494#endif
3495
3496#if defined(FIRST)
3497struct S2 {
3498 S2() = default;
3499};
3500S2 s2a = S2();
3501#elif defined(SECOND)
3502struct S2 {
3503 S2() = default;
3504};
3505#else
3506S2 s2;
3507#endif
3508
3509#if defined(FIRST)
3510struct S3 {
3511 S3() = delete;
3512};
3513S3* s3c;
3514#elif defined(SECOND)
3515struct S3 {
3516 S3() = delete;
3517};
3518#else
3519S3* s3;
3520#endif
3521
3522#if defined(FIRST) || defined(SECOND)
3523int F1(int x, float y = 2.7) { return 1; }
3524#else
3525int I1 = F1(1);
3526#endif
3527
3528#if defined(FIRST)
3529int F2() { return 1; }
3530#elif defined(SECOND)
3531double F2() { return 1; }
3532#else
3533int I2 = F2();
3534// expected-error@-1 {{call to 'F2' is ambiguous}}
3535// expected-note@first.h:* {{candidate function}}
3536// expected-note@second.h:* {{candidate function}}
3537#endif
3538
3539#if defined(FIRST)
3540int F3(float) { return 1; }
3541#elif defined(SECOND)
3542int F3(double) { return 1; }
3543#else
3544int I3 = F3(1);
3545// expected-error@-1 {{call to 'F3' is ambiguous}}
3546// expected-note@first.h:* {{candidate function}}
3547// expected-note@second.h:* {{candidate function}}
3548#endif
3549
3550#if defined(FIRST)
3551int F4(int x) { return 1; }
3552#elif defined(SECOND)
3553int F4(int y) { return 1; }
3554#else
3555int I4 = F4(1);
3556// expected-error@second.h:* {{'FunctionDecl::F4' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with name 'y'}}
3557// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with name 'x'}}
3558#endif
3559
3560#if defined(FIRST)
3561int F5(int x) { return 1; }
3562#elif defined(SECOND)
3563int F5(int x = 1) { return 1; }
3564#else
3565int I5 = F6(1);
3566// 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}}
3567// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a default argument}}
3568#endif
3569
3570#if defined(FIRST)
3571int F6(int x = 2) { return 1; }
3572#elif defined(SECOND)
3573int F6(int x = 1) { return 1; }
3574#else
3575int I6 = F6(1);
3576// 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}}
3577// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a different default argument}}
3578#endif
3579
3580using I = int;
3581#if defined(FIRST)
3582I F7() { return 0; }
3583#elif defined(SECOND)
3584int F7() { return 0; }
3585#else
3586int I7 = F7();
3587// expected-error@second.h:* {{'FunctionDecl::F7' has different definitions in different modules; definition in module 'SecondModule' first difference is return type is 'int'}}
3588// expected-note@first.h:* {{but in 'FirstModule' found different return type 'FunctionDecl::I' (aka 'int')}}
3589#endif
3590
3591#if defined(FIRST)
3592int F8(int) { return 0; }
3593#elif defined(SECOND)
3594int F8(I) { return 0; }
3595#else
3596int I8 = F8(1);
3597// 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')}}
3598// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int'}}
3599#endif
3600
3601#if defined(FIRST)
3602int F9(int[1]) { return 0; }
3603#elif defined(SECOND)
3604int F9(int[2]) { return 0; }
3605#else
3606int I9 = F9(nullptr);
3607// 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]'}}
3608// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int *' decayed from 'int [1]'}}
3609#endif
3610
3611#if defined(FIRST)
3612int F10() { return 1; }
3613#elif defined(SECOND)
3614int F10() { return 2; }
3615#else
3616int I10 = F10();
3617#endif
3618// expected-error@second.h:* {{'FunctionDecl::F10' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3619// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
Richard Trieu5d014062018-06-07 00:20:58 +00003620
3621#if defined(FIRST)
3622struct S11 {
3623 template <int> void foo();
3624};
3625#elif defined(SECOND)
3626struct S11 {
3627 template <int> void foo();
3628};
3629template <int> void S11::foo() {}
3630#else
3631S11 s11;
3632#endif
3633
Richard Trieue6caa262017-12-23 00:41:01 +00003634} // namespace FunctionDecl
3635
Richard Trieu4d06bef2018-02-13 19:53:40 +00003636namespace DeclTemplateArguments {
3637#if defined(FIRST)
3638int foo() { return 1; }
3639int bar() { return foo(); }
3640#elif defined(SECOND)
3641template <class T = int>
3642int foo() { return 2; }
3643int bar() { return foo<>(); }
3644#else
3645int num = bar();
3646// expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3647// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3648#endif
3649}
3650
Richard Trieue7f7ed22017-02-22 01:11:25 +00003651// Keep macros contained to one file.
3652#ifdef FIRST
3653#undef FIRST
3654#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003655
Richard Trieue7f7ed22017-02-22 01:11:25 +00003656#ifdef SECOND
3657#undef SECOND
3658#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00003659
3660#ifdef ACCESS
3661#undef ACCESS
3662#endif