blob: e4c5ba6f82a8467880b0e380a969f0f0c0270cc4 [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 Trieua7f38f72018-09-05 21:55:09 +000028// RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -std=c++1z \
29// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
30// RUN: -I%t/Inputs -verify %s
Richard Trieue7f7ed22017-02-22 01:11:25 +000031
32#if !defined(FIRST) && !defined(SECOND)
33#include "first.h"
34#include "second.h"
35#endif
36
Richard Trieu73cf9242017-11-04 01:20:50 +000037// Used for testing
38#if defined(FIRST)
39#define ACCESS public:
40#elif defined(SECOND)
41#define ACCESS private:
42#endif
43
Richard Trieue7f7ed22017-02-22 01:11:25 +000044namespace AccessSpecifiers {
45#if defined(FIRST)
46struct S1 {
47};
48#elif defined(SECOND)
49struct S1 {
50 private:
51};
52#else
53S1 s1;
54// expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
55// expected-note@first.h:* {{but in 'FirstModule' found end of class}}
56#endif
57
58#if defined(FIRST)
59struct S2 {
60 public:
61};
62#elif defined(SECOND)
63struct S2 {
64 protected:
65};
66#else
67S2 s2;
68// expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}}
69// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
70#endif
Richard Trieu73cf9242017-11-04 01:20:50 +000071
72#define DECLS \
73public: \
74private: \
75protected:
76
77#if defined(FIRST) || defined(SECOND)
78struct Valid1 {
79 DECLS
80};
81#else
82Valid1 v1;
83#endif
84
85#if defined(FIRST) || defined(SECOND)
86struct Invalid1 {
87 DECLS
88 ACCESS
89};
90#else
91Invalid1 i1;
92// expected-error@second.h:* {{'AccessSpecifiers::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
93// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
94#endif
95
96#undef DECLS
Richard Trieue7f7ed22017-02-22 01:11:25 +000097} // namespace AccessSpecifiers
98
Richard Trieu639d7b62017-02-22 22:22:42 +000099namespace StaticAssert {
100#if defined(FIRST)
101struct S1 {
102 static_assert(1 == 1, "First");
103};
104#elif defined(SECOND)
105struct S1 {
106 static_assert(1 == 1, "Second");
107};
108#else
109S1 s1;
110// expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}}
111// expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}}
112#endif
113
114#if defined(FIRST)
115struct S2 {
116 static_assert(2 == 2, "Message");
117};
118#elif defined(SECOND)
119struct S2 {
120 static_assert(2 == 2);
121};
122#else
123S2 s2;
124// 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}}
125// expected-note@first.h:* {{but in 'FirstModule' found static assert with message}}
126#endif
127
128#if defined(FIRST)
129struct S3 {
130 static_assert(3 == 3, "Message");
131};
132#elif defined(SECOND)
133struct S3 {
134 static_assert(3 != 4, "Message");
135};
136#else
137S3 s3;
138// expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}}
139// expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}}
140#endif
141
142#if defined(FIRST)
143struct S4 {
144 static_assert(4 == 4, "Message");
145};
146#elif defined(SECOND)
147struct S4 {
148 public:
149};
150#else
151S4 s4;
152// expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
153// expected-note@first.h:* {{but in 'FirstModule' found static assert}}
154#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000155
156#define DECLS \
157 static_assert(4 == 4, "Message"); \
158 static_assert(5 == 5);
159
160#if defined(FIRST) || defined(SECOND)
161struct Valid1 {
162 DECLS
163};
164#else
165Valid1 v1;
166#endif
167
168#if defined(FIRST) || defined(SECOND)
169struct Invalid1 {
170 DECLS
171 ACCESS
172};
173#else
174Invalid1 i1;
175// expected-error@second.h:* {{'StaticAssert::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
176// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
177#endif
178#undef DECLS
179} // namespace StaticAssert
Richard Trieu639d7b62017-02-22 22:22:42 +0000180
Richard Trieud0786092017-02-23 00:23:01 +0000181namespace Field {
182#if defined(FIRST)
183struct S1 {
184 int x;
185 private:
186 int y;
187};
188#elif defined(SECOND)
189struct S1 {
190 int x;
191 int y;
192};
193#else
194S1 s1;
195// expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
196// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
197#endif
198
199#if defined(FIRST)
200struct S2 {
201 int x;
202 int y;
203};
204#elif defined(SECOND)
205struct S2 {
206 int y;
207 int x;
208};
209#else
210S2 s2;
211// expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
212// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
213#endif
Richard Trieubcaaf962017-02-23 03:25:57 +0000214
215#if defined(FIRST)
216struct S3 {
217 double x;
218};
219#elif defined(SECOND)
220struct S3 {
221 int x;
222};
223#else
224S3 s3;
225// expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}}
226// expected-note@second.h:* {{declaration of 'x' does not match}}
227#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000228
229#if defined(FIRST)
230typedef int A;
231struct S4 {
232 A x;
233};
234
235struct S5 {
236 A x;
237};
238#elif defined(SECOND)
239typedef int B;
240struct S4 {
241 B x;
242};
243
244struct S5 {
245 int x;
246};
247#else
248S4 s4;
Alex Lorenz76377dc2017-03-10 15:04:58 +0000249// 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')}}
250// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000251
252S5 s5;
253// 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 +0000254// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
Richard Trieu8459ddf2017-02-24 02:59:12 +0000255#endif
256
Richard Trieu93772fc2017-02-24 20:59:28 +0000257#if defined(FIRST)
258struct S6 {
259 unsigned x;
260};
261#elif defined(SECOND)
262struct S6 {
263 unsigned x : 1;
264};
265#else
266S6 s6;
267// expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}}
268// expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}}
269#endif
270
271#if defined(FIRST)
272struct S7 {
273 unsigned x : 2;
274};
275#elif defined(SECOND)
276struct S7 {
277 unsigned x : 1;
278};
279#else
280S7 s7;
281// 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}}
282// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
283#endif
284
285#if defined(FIRST)
286struct S8 {
287 unsigned x : 2;
288};
289#elif defined(SECOND)
290struct S8 {
291 unsigned x : 1 + 1;
292};
293#else
294S8 s8;
295// 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}}
296// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
297#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000298
Richard Trieu8d543e22017-02-24 23:35:37 +0000299#if defined(FIRST)
300struct S9 {
301 mutable int x;
302};
303#elif defined(SECOND)
304struct S9 {
305 int x;
306};
307#else
308S9 s9;
309// expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
310// expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}}
311#endif
312
313#if defined(FIRST)
314struct S10 {
315 unsigned x = 5;
316};
317#elif defined(SECOND)
318struct S10 {
319 unsigned x;
320};
321#else
322S10 s10;
323// 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}}
324// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}}
325#endif
326
327#if defined(FIRST)
328struct S11 {
329 unsigned x = 5;
330};
331#elif defined(SECOND)
332struct S11 {
333 unsigned x = 7;
334};
335#else
336S11 s11;
337// 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}}
338// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
339#endif
340
Richard Trieu02552272017-05-02 23:58:52 +0000341#if defined(FIRST)
342struct S12 {
343 unsigned x[5];
344};
345#elif defined(SECOND)
346struct S12 {
347 unsigned x[7];
348};
349#else
350S12 s12;
351// expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}}
352// expected-note@second.h:* {{declaration of 'x' does not match}}
353#endif
354
355#if defined(FIRST)
356struct S13 {
357 unsigned x[7];
358};
359#elif defined(SECOND)
360struct S13 {
361 double x[7];
362};
363#else
364S13 s13;
365// expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}}
366// expected-note@second.h:* {{declaration of 'x' does not match}}
367#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000368
369#define DECLS \
370 int a; \
371 int b : 3; \
372 unsigned c : 1 + 2; \
373 s d; \
374 double e = 1.0; \
375 long f[5];
376
377#if defined(FIRST) || defined(SECOND)
378typedef short s;
379#endif
380
381#if defined(FIRST) || defined(SECOND)
382struct Valid1 {
383 DECLS
384};
385#else
386Valid1 v1;
387#endif
388
389#if defined(FIRST) || defined(SECOND)
390struct Invalid1 {
391 DECLS
392 ACCESS
393};
394#else
395Invalid1 i1;
396// expected-error@second.h:* {{'Field::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
397// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
398#endif
399#undef DECLS
Richard Trieud0786092017-02-23 00:23:01 +0000400} // namespace Field
401
Richard Trieu48143742017-02-28 21:24:38 +0000402namespace Method {
403#if defined(FIRST)
404struct S1 {
405 void A() {}
406};
407#elif defined(SECOND)
408struct S1 {
409 private:
410 void A() {}
411};
412#else
413S1 s1;
414// expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
415// expected-note@first.h:* {{but in 'FirstModule' found method}}
416#endif
417
418#if defined(FIRST)
419struct S2 {
420 void A() {}
421 void B() {}
422};
423#elif defined(SECOND)
424struct S2 {
425 void B() {}
426 void A() {}
427};
428#else
429S2 s2;
430// expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
431// expected-note@first.h:* {{but in 'FirstModule' found method 'A'}}
432#endif
Richard Trieu583e2c12017-03-04 00:08:58 +0000433
434#if defined(FIRST)
435struct S3 {
436 static void A() {}
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000437 void A(int) {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000438};
439#elif defined(SECOND)
440struct S3 {
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000441 void A(int) {}
442 static void A() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000443};
444#else
445S3 s3;
446// 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}}
447// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}}
448#endif
449
450#if defined(FIRST)
451struct S4 {
452 virtual void A() {}
453 void B() {}
454};
455#elif defined(SECOND)
456struct S4 {
457 void A() {}
458 virtual void B() {}
459};
460#else
461S4 s4;
462// 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}}
463// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}}
464#endif
465
466#if defined(FIRST)
467struct S5 {
468 virtual void A() = 0;
469 virtual void B() {};
470};
471#elif defined(SECOND)
472struct S5 {
473 virtual void A() {}
474 virtual void B() = 0;
475};
476#else
477S5 *s5;
478// expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
479// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}}
480#endif
481
482#if defined(FIRST)
483struct S6 {
484 inline void A() {}
485};
486#elif defined(SECOND)
487struct S6 {
488 void A() {}
489};
490#else
491S6 s6;
492// 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}}
493// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}}
494#endif
495
496#if defined(FIRST)
497struct S7 {
498 void A() volatile {}
499 void A() {}
500};
501#elif defined(SECOND)
502struct S7 {
503 void A() {}
504 void A() volatile {}
505};
506#else
507S7 s7;
508// 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}}
509// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}}
510#endif
511
512#if defined(FIRST)
513struct S8 {
514 void A() const {}
515 void A() {}
516};
517#elif defined(SECOND)
518struct S8 {
519 void A() {}
520 void A() const {}
521};
522#else
523S8 s8;
524// 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}}
525// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}}
526#endif
527
Richard Trieu02552272017-05-02 23:58:52 +0000528#if defined(FIRST)
529struct S9 {
530 void A(int x) {}
531 void A(int x, int y) {}
532};
533#elif defined(SECOND)
534struct S9 {
535 void A(int x, int y) {}
536 void A(int x) {}
537};
538#else
539S9 s9;
540// 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}}
541// expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}}
542#endif
543
544#if defined(FIRST)
545struct S10 {
546 void A(int x) {}
547 void A(float x) {}
548};
549#elif defined(SECOND)
550struct S10 {
551 void A(float x) {}
552 void A(int x) {}
553};
554#else
555S10 s10;
556// 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'}}
557// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}}
558#endif
559
560#if defined(FIRST)
561struct S11 {
Richard Trieue6caa262017-12-23 00:41:01 +0000562 void A(int x);
Richard Trieu02552272017-05-02 23:58:52 +0000563};
564#elif defined(SECOND)
565struct S11 {
Richard Trieue6caa262017-12-23 00:41:01 +0000566 void A(int y);
Richard Trieu02552272017-05-02 23:58:52 +0000567};
568#else
569S11 s11;
570// 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'}}
571// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}}
572#endif
573
574#if defined(FIRST)
575struct S12 {
Richard Trieue6caa262017-12-23 00:41:01 +0000576 void A(int x);
Richard Trieu02552272017-05-02 23:58:52 +0000577};
578#elif defined(SECOND)
579struct S12 {
Richard Trieue6caa262017-12-23 00:41:01 +0000580 void A(int x = 1);
Richard Trieu02552272017-05-02 23:58:52 +0000581};
582#else
583S12 s12;
Richard Trieu6e13ff32017-06-16 02:44:29 +0000584// 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}}
585// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}}
Richard Trieu02552272017-05-02 23:58:52 +0000586#endif
587
588#if defined(FIRST)
589struct S13 {
Richard Trieue6caa262017-12-23 00:41:01 +0000590 void A(int x = 1 + 0);
Richard Trieu02552272017-05-02 23:58:52 +0000591};
592#elif defined(SECOND)
593struct S13 {
Richard Trieue6caa262017-12-23 00:41:01 +0000594 void A(int x = 1);
Richard Trieu02552272017-05-02 23:58:52 +0000595};
596#else
597S13 s13;
Richard Trieu6e13ff32017-06-16 02:44:29 +0000598// 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}}
599// 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 +0000600#endif
601
602#if defined(FIRST)
603struct S14 {
Richard Trieue6caa262017-12-23 00:41:01 +0000604 void A(int x[2]);
Richard Trieu02552272017-05-02 23:58:52 +0000605};
606#elif defined(SECOND)
607struct S14 {
Richard Trieue6caa262017-12-23 00:41:01 +0000608 void A(int x[3]);
Richard Trieu02552272017-05-02 23:58:52 +0000609};
610#else
611S14 s14;
612// 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]'}}
613// expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}}
614#endif
Richard Trieu9747a7c2017-07-14 01:36:41 +0000615
616#if defined(FIRST)
617struct S15 {
618 int A() { return 0; }
619};
620#elif defined(SECOND)
621struct S15 {
622 long A() { return 0; }
623};
624#else
625S15 s15;
626// expected-error@first.h:* {{'Method::S15::A' from module 'FirstModule' is not present in definition of 'Method::S15' in module 'SecondModule'}}
627// expected-note@second.h:* {{declaration of 'A' does not match}}
628#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000629
630#define DECLS \
631 void A(); \
632 static void B(); \
633 virtual void C(); \
634 virtual void D() = 0; \
635 inline void E(); \
636 void F() const; \
637 void G() volatile; \
638 void H(int x); \
639 void I(int x = 5 + 5); \
640 void J(int); \
641 void K(int x[2]); \
642 int L();
643
644#if defined(FIRST) || defined(SECOND)
645struct Valid1 {
646 DECLS
647};
648#else
649Valid1* v1;
650#endif
651
652#if defined(FIRST) || defined(SECOND)
653struct Invalid1 {
654 DECLS
655 ACCESS
656};
657#else
658Invalid1* i1;
659// expected-error@second.h:* {{'Method::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
660// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
661#endif
662#undef DECLS
Richard Trieu48143742017-02-28 21:24:38 +0000663} // namespace Method
664
Richard Trieu27c1b1a2018-07-10 01:40:50 +0000665namespace MethodBody {
666#if defined(FIRST)
667struct S1 {
668 int A() { return 0; }
669};
670#elif defined(SECOND)
671struct S1 {
672 int A() { return 0; }
673};
674#else
675S1 s1;
676#endif
677
678#if defined(FIRST)
679struct S2 {
680 int BothBodies() { return 0; }
681};
682#elif defined(SECOND)
683struct S2 {
684 int BothBodies() { return 1; }
685};
686#else
687S2 s2;
688// expected-error@first.h:* {{'MethodBody::S2' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'BothBodies' with body}}
689// expected-note@second.h:* {{but in 'SecondModule' found method 'BothBodies' with different body}}
690#endif
691
692#if defined(FIRST)
693struct S3 {
694 int FirstBody() { return 0; }
695};
696#elif defined(SECOND)
697struct S3 {
698 int FirstBody();
699};
700#else
701S3 s3;
702// expected-error@first.h:* {{'MethodBody::S3' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstBody' with body}}
703// expected-note@second.h:* {{but in 'SecondModule' found method 'FirstBody' with no body}}
704#endif
705
706#if defined(FIRST)
707struct S4 {
708 int SecondBody();
709};
710#elif defined(SECOND)
711struct S4 {
712 int SecondBody() { return 0; }
713};
714#else
715S4 s4;
716// expected-error@first.h:* {{'MethodBody::S4' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'SecondBody' with no body}}
717// expected-note@second.h:* {{but in 'SecondModule' found method 'SecondBody' with body}}
718#endif
719
720#if defined(FIRST)
721struct S5 {
722 int FirstBodySecondOutOfLine() { return 0; }
723};
724#elif defined(SECOND)
725struct S5 {
726 int FirstBodySecondOutOfLine();
727};
728int S5::FirstBodySecondOutOfLine() { return 0; }
729#else
730S5 s5;
731// expected-error@second.h:* {{'MethodBody::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'FirstBodySecondOutOfLine' with no body}}
732// expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}}
733#endif
734
735#if defined(FIRST)
736struct S6 {
737 int FirstOutOfLineSecondBody();
738};
739int S6::FirstOutOfLineSecondBody() { return 0; }
740#elif defined(SECOND)
741struct S6 {
742 int FirstOutOfLineSecondBody() { return 0; }
743};
744#else
745S6 s6;
746// expected-error@first.h:* {{'MethodBody::S6' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstOutOfLineSecondBody' with no body}}
747// expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}}
748#endif
749
750#if defined(FIRST)
751struct S7 {
752 int BothOutOfLine();
753};
754int S7::BothOutOfLine() { return 1; }
755#elif defined(SECOND)
756struct S7 {
757 int BothOutOfLine();
758};
759int S7::BothOutOfLine() { return 0; }
760#else
761S7 s7;
762// expected-error@second.h:* {{'MethodBody::S7::BothOutOfLine' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
763// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
764#endif
765
766#if defined(FIRST)
767struct S8 {
768 int FirstBodySecondOutOfLine() { return 0; }
769};
770#elif defined(SECOND)
771struct S8 {
772 int FirstBodySecondOutOfLine();
773};
774int S8::FirstBodySecondOutOfLine() { return 1; }
775#else
776S8 s8;
777// expected-error@second.h:* {{'MethodBody::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'FirstBodySecondOutOfLine' with no body}}
778// expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}}
779#endif
780
781#if defined(FIRST)
782struct S9 {
783 int FirstOutOfLineSecondBody();
784};
785int S9::FirstOutOfLineSecondBody() { return 1; }
786#elif defined(SECOND)
787struct S9 {
788 int FirstOutOfLineSecondBody() { return 0; }
789};
790#else
791S9 s9;
792// expected-error@first.h:* {{'MethodBody::S9' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstOutOfLineSecondBody' with no body}}
793// expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}}
794#endif
795
796#if defined(FIRST)
797struct S10 {
798 S10(int);
799 S10() = delete;
800};
801#elif defined(SECOND)
802struct S10 {
803 S10(int);
804 S10();
805};
806#else
807S10 s10(10);
808// expected-error@first.h:* {{'MethodBody::S10' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is deleted}}
809// expected-note@second.h:* {{but in 'SecondModule' found constructor is not deleted}}
810#endif
811
812#if defined(FIRST)
813struct S11 {
814 S11() = default;
815};
816#elif defined(SECOND)
817struct S11 {
818 S11();
819};
820#else
821S11 s11;
822// expected-error@first.h:* {{'MethodBody::S11' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is defaulted}}
823// expected-note@second.h:* {{but in 'SecondModule' found constructor is not defaulted}}
824#endif
825
826#define DECLS(CLASSNAME) \
827 CLASSNAME() = default; \
828 ~CLASSNAME() = delete; \
829 void A(); \
830 void B() { return; }; \
831 void C(); \
832 void D();
833
834#define OUTOFLINEDEFS(CLASSNAME) \
835 void CLASSNAME::C() {} \
836 void CLASSNAME::D() { return; }
837
838#if defined(FIRST) || defined(SECOND)
839struct Valid1 {
840 DECLS(Valid1)
841};
842OUTOFLINEDEFS(Valid1)
843#else
844Valid1* v1;
845#endif
846
847#if defined(FIRST) || defined(SECOND)
848struct Invalid1 {
849 DECLS(Invalid1)
850 ACCESS
851};
852OUTOFLINEDEFS(Invalid1)
853#else
854Invalid1* i1;
855// expected-error@first.h:* {{'MethodBody::Invalid1' has different definitions in different modules; first difference is definition in module 'FirstModule' found public access specifier}}
856// expected-note@second.h:* {{but in 'SecondModule' found private access specifier}}
857#endif
858#undef DECLS
859} // namespace MethodBody
860
Richard Trieu1c71d512017-07-15 02:55:13 +0000861namespace Constructor {
862#if defined(FIRST)
863struct S1 {
864 S1() {}
865 void foo() {}
866};
867#elif defined(SECOND)
868struct S1 {
869 void foo() {}
870 S1() {}
871};
872#else
873S1 s1;
874// expected-error@second.h:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}}
875// expected-note@first.h:* {{but in 'FirstModule' found constructor}}
876#endif
877
878#if defined(FIRST)
879struct S2 {
880 S2(int) {}
881 S2(int, int) {}
882};
883#elif defined(SECOND)
884struct S2 {
885 S2(int, int) {}
886 S2(int) {}
887};
888#else
889S2* s2;
890// 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}}
891// expected-note@first.h:* {{but in 'FirstModule' found constructor that has 1 parameter}}
892#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000893
894#define DECLS(CLASS) \
895 CLASS(int); \
896 CLASS(double); \
897 CLASS(int, int);
898
899#if defined(FIRST) || defined(SECOND)
900struct Valid1 {
901 DECLS(Valid1)
902};
903#else
904Valid1* v1;
905#endif
906
907#if defined(FIRST) || defined(SECOND)
908struct Invalid1 {
909 DECLS(Invalid1)
910 ACCESS
911};
912#else
913Invalid1* i1;
914// expected-error@second.h:* {{'Constructor::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 Trieu1c71d512017-07-15 02:55:13 +0000918} // namespace Constructor
919
920namespace Destructor {
921#if defined(FIRST)
922struct S1 {
923 ~S1() {}
924 S1() {}
925};
926#elif defined(SECOND)
927struct S1 {
928 S1() {}
929 ~S1() {}
930};
931#else
932S1 s1;
933// expected-error@second.h:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}}
934// expected-note@first.h:* {{but in 'FirstModule' found destructor}}
935#endif
936
937#if defined(FIRST)
938struct S2 {
939 virtual ~S2() {}
940 void foo() {}
941};
942#elif defined(SECOND)
943struct S2 {
944 ~S2() {}
945 virtual void foo() {}
946};
947#else
948S2 s2;
949// expected-error@second.h:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}}
950// expected-note@first.h:* {{but in 'FirstModule' found destructor is virtual}}
951#endif
952
Richard Trieu73cf9242017-11-04 01:20:50 +0000953#if defined(FIRST) || defined(SECOND)
954struct Valid1 {
955 ~Valid1();
Richard Trieue7f7ed22017-02-22 01:11:25 +0000956};
Richard Trieu73cf9242017-11-04 01:20:50 +0000957#else
958Valid1 v1;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000959#endif
Richard Trieu73cf9242017-11-04 01:20:50 +0000960
961#if defined(FIRST) || defined(SECOND)
962struct Invalid1 {
963 ~Invalid1();
964 ACCESS
965};
966#else
967Invalid1 i1;
968// expected-error@second.h:* {{'Destructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
969// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
970#endif
971
972#if defined(FIRST) || defined(SECOND)
973struct Valid2 {
974 virtual ~Valid2();
975};
976#else
977Valid2 v2;
978#endif
979
980#if defined(FIRST) || defined(SECOND)
981struct Invalid2 {
982 virtual ~Invalid2();
983 ACCESS
984};
985#else
986Invalid2 i2;
987// expected-error@second.h:* {{'Destructor::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
988// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
989#endif
990} // namespace Destructor
Richard Trieue7f7ed22017-02-22 01:11:25 +0000991
Richard Trieu33562c22017-03-08 00:13:19 +0000992namespace TypeDef {
993#if defined(FIRST)
994struct S1 {
995 typedef int a;
996};
997#elif defined(SECOND)
998struct S1 {
999 typedef double a;
1000};
1001#else
1002S1 s1;
1003// expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
1004// expected-note@second.h:* {{declaration of 'a' does not match}}
1005#endif
1006
1007#if defined(FIRST)
1008struct S2 {
1009 typedef int a;
1010};
1011#elif defined(SECOND)
1012struct S2 {
1013 typedef int b;
1014};
1015#else
1016S2 s2;
1017// expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
1018// expected-note@second.h:* {{definition has no member 'a'}}
1019#endif
1020
1021#if defined(FIRST)
1022typedef int T;
1023struct S3 {
1024 typedef T a;
1025};
1026#elif defined(SECOND)
1027typedef double T;
1028struct S3 {
1029 typedef T a;
1030};
1031#else
1032S3 s3;
1033// expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
1034// expected-note@second.h:* {{declaration of 'a' does not match}}
1035#endif
Richard Trieu11d566a2017-06-12 21:58:22 +00001036
1037#if defined(FIRST)
1038struct S4 {
1039 typedef int a;
1040 typedef int b;
1041};
1042#elif defined(SECOND)
1043struct S4 {
1044 typedef int b;
1045 typedef int a;
1046};
1047#else
1048S4 s4;
1049// expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}}
1050// expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}}
1051#endif
1052
1053#if defined(FIRST)
1054struct S5 {
1055 typedef int a;
1056 typedef int b;
1057 int x;
1058};
1059#elif defined(SECOND)
1060struct S5 {
1061 int x;
1062 typedef int b;
1063 typedef int a;
1064};
1065#else
1066S5 s5;
1067// expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
1068// expected-note@first.h:* {{but in 'FirstModule' found typedef}}
1069#endif
1070
1071#if defined(FIRST)
1072typedef float F;
1073struct S6 {
1074 typedef int a;
1075 typedef F b;
1076};
1077#elif defined(SECOND)
1078struct S6 {
1079 typedef int a;
1080 typedef float b;
1081};
1082#else
1083S6 s6;
1084// 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'}}
1085// expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'TypeDef::F' (aka 'float')}}
1086#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001087
1088#define DECLS \
1089 typedef int A; \
1090 typedef double B; \
1091 typedef I C;
1092
1093#if defined(FIRST) || defined(SECOND)
1094typedef int I;
1095#endif
1096
1097#if defined(FIRST) || defined(SECOND)
1098struct Valid1 {
1099 DECLS
1100};
1101#else
1102Valid1 v1;
1103#endif
1104
1105#if defined(FIRST) || defined(SECOND)
1106struct Invalid1 {
1107 DECLS
1108 ACCESS
1109};
1110#else
1111Invalid1 i1;
1112// expected-error@second.h:* {{'TypeDef::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1113// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1114#endif
1115#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +00001116} // namespace TypeDef
1117
1118namespace Using {
1119#if defined(FIRST)
1120struct S1 {
1121 using a = int;
1122};
1123#elif defined(SECOND)
1124struct S1 {
1125 using a = double;
1126};
1127#else
1128S1 s1;
1129// expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
1130// expected-note@second.h:* {{declaration of 'a' does not match}}
1131#endif
1132
1133#if defined(FIRST)
1134struct S2 {
1135 using a = int;
1136};
1137#elif defined(SECOND)
1138struct S2 {
1139 using b = int;
1140};
1141#else
1142S2 s2;
1143// expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
1144// expected-note@second.h:* {{definition has no member 'a'}}
1145#endif
1146
1147#if defined(FIRST)
1148typedef int T;
1149struct S3 {
1150 using a = T;
1151};
1152#elif defined(SECOND)
1153typedef double T;
1154struct S3 {
1155 using a = T;
1156};
1157#else
1158S3 s3;
1159// expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
1160// expected-note@second.h:* {{declaration of 'a' does not match}}
1161#endif
Richard Trieu11d566a2017-06-12 21:58:22 +00001162
1163#if defined(FIRST)
1164struct S4 {
1165 using a = int;
1166 using b = int;
1167};
1168#elif defined(SECOND)
1169struct S4 {
1170 using b = int;
1171 using a = int;
1172};
1173#else
1174S4 s4;
1175// expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}}
1176// expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}}
1177#endif
1178
1179#if defined(FIRST)
1180struct S5 {
1181 using a = int;
1182 using b = int;
1183 int x;
1184};
1185#elif defined(SECOND)
1186struct S5 {
1187 int x;
1188 using b = int;
1189 using a = int;
1190};
1191#else
1192S5 s5;
1193// expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
1194// expected-note@first.h:* {{but in 'FirstModule' found type alias}}
1195#endif
1196
1197#if defined(FIRST)
1198typedef float F;
1199struct S6 {
1200 using a = int;
1201 using b = F;
1202};
1203#elif defined(SECOND)
1204struct S6 {
1205 using a = int;
1206 using b = float;
1207};
1208#else
1209S6 s6;
1210// 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'}}
1211// expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'Using::F' (aka 'float')}}
1212#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001213
1214#if defined(FIRST) || defined(SECOND)
1215using I = int;
1216#endif
1217
1218#define DECLS \
1219 using A = int; \
1220 using B = double; \
1221 using C = I;
1222
1223#if defined(FIRST) || defined(SECOND)
1224struct Valid1 {
1225 DECLS
1226};
1227#else
1228Valid1 v1;
1229#endif
1230
1231#if defined(FIRST) || defined(SECOND)
1232struct Invalid1 {
1233 DECLS
1234 ACCESS
1235};
1236#else
1237Invalid1 i1;
1238// expected-error@second.h:* {{'Using::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1239// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1240#endif
1241#undef DECLS
Richard Trieu33562c22017-03-08 00:13:19 +00001242} // namespace Using
1243
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001244namespace RecordType {
1245#if defined(FIRST)
1246struct B1 {};
1247struct S1 {
1248 B1 x;
1249};
1250#elif defined(SECOND)
1251struct A1 {};
1252struct S1 {
1253 A1 x;
1254};
1255#else
1256S1 s1;
1257// expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
1258// expected-note@second.h:* {{declaration of 'x' does not match}}
1259#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001260
1261#define DECLS \
1262 Foo F;
1263
1264#if defined(FIRST) || defined(SECOND)
1265struct Foo {};
1266#endif
1267
1268#if defined(FIRST) || defined(SECOND)
1269struct Valid1 {
1270 DECLS
1271};
1272#else
1273Valid1 v1;
1274#endif
1275
1276#if defined(FIRST) || defined(SECOND)
1277struct Invalid1 {
1278 DECLS
1279 ACCESS
1280};
1281#else
1282Invalid1 i1;
1283// expected-error@second.h:* {{'RecordType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1284// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1285#endif
1286#undef DECLS
1287} // namespace RecordType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001288
1289namespace DependentType {
1290#if defined(FIRST)
1291template <class T>
1292class S1 {
1293 typename T::typeA x;
1294};
1295#elif defined(SECOND)
1296template <class T>
1297class S1 {
1298 typename T::typeB x;
1299};
1300#else
1301template<class T>
1302using U1 = S1<T>;
1303// expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
1304// expected-note@second.h:* {{declaration of 'x' does not match}}
1305#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001306
1307#define DECLS \
1308 typename T::typeA x;
1309
1310#if defined(FIRST) || defined(SECOND)
1311template <class T>
1312struct Valid1 {
1313 DECLS
1314};
1315#else
1316template <class T>
1317using V1 = Valid1<T>;
1318#endif
1319
1320#if defined(FIRST) || defined(SECOND)
1321template <class T>
1322struct Invalid1 {
1323 DECLS
1324 ACCESS
1325};
1326#else
1327template <class T>
1328using I1 = Invalid1<T>;
1329// expected-error@second.h:* {{'DependentType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1330// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1331#endif
1332#undef DECLS
1333} // namespace DependentType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001334
1335namespace ElaboratedType {
1336#if defined(FIRST)
1337namespace N1 { using type = double; }
1338struct S1 {
1339 N1::type x;
1340};
1341#elif defined(SECOND)
1342namespace N1 { using type = int; }
1343struct S1 {
1344 N1::type x;
1345};
1346#else
1347S1 s1;
1348// expected-error@first.h:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}}
1349// expected-note@second.h:* {{declaration of 'x' does not match}}
1350#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001351
1352#define DECLS \
1353 NS::type x;
1354
1355#if defined(FIRST) || defined(SECOND)
1356namespace NS { using type = float; }
1357#endif
1358
1359#if defined(FIRST) || defined(SECOND)
1360struct Valid1 {
1361 DECLS
1362};
1363#else
1364Valid1 v1;
1365#endif
1366
1367#if defined(FIRST) || defined(SECOND)
1368struct Invalid1 {
1369 DECLS
1370 ACCESS
1371};
1372#else
1373Invalid1 i1;
1374// expected-error@second.h:* {{'ElaboratedType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1375// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1376#endif
1377#undef DECLS
1378} // namespace ElaboratedType
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001379
1380namespace Enum {
1381#if defined(FIRST)
1382enum A1 {};
1383struct S1 {
1384 A1 x;
1385};
1386#elif defined(SECOND)
1387enum A2 {};
1388struct S1 {
1389 A2 x;
1390};
1391#else
1392S1 s1;
1393// expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
1394// expected-note@second.h:* {{declaration of 'x' does not match}}
1395#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001396
1397#define DECLS \
1398 E e = E1;
1399
1400#if defined(FIRST) || defined(SECOND)
1401enum E { E1, E2 };
1402#endif
1403
1404#if defined(FIRST) || defined(SECOND)
1405struct Valid1 {
1406 DECLS
1407};
1408#else
1409Valid1 v1;
1410#endif
1411
1412#if defined(FIRST) || defined(SECOND)
1413struct Invalid1 {
1414 DECLS
1415 ACCESS
1416};
1417#else
1418Invalid1 i1;
1419// expected-error@second.h:* {{'Enum::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1420// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1421#endif
1422#undef DECLS
Richard Trieu58bb7bd2017-05-17 02:29:02 +00001423}
Hans Wennborg22707762017-04-12 16:40:26 +00001424
Richard Trieuce81b192017-05-17 03:23:35 +00001425namespace NestedNamespaceSpecifier {
1426#if defined(FIRST)
1427namespace LevelA1 {
1428using Type = int;
1429}
1430
1431struct S1 {
1432 LevelA1::Type x;
1433};
1434# elif defined(SECOND)
1435namespace LevelB1 {
1436namespace LevelC1 {
1437using Type = int;
1438}
1439}
1440
1441struct S1 {
1442 LevelB1::LevelC1::Type x;
1443};
1444#else
1445S1 s1;
1446// 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')}}
1447// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
1448#endif
1449
1450#if defined(FIRST)
1451namespace LevelA2 { using Type = int; }
1452struct S2 {
1453 LevelA2::Type x;
1454};
1455# elif defined(SECOND)
1456struct S2 {
1457 int x;
1458};
1459#else
1460S2 s2;
1461// 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'}}
1462// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
1463#endif
1464
1465namespace LevelA3 { using Type = int; }
1466namespace LevelB3 { using Type = int; }
1467#if defined(FIRST)
1468struct S3 {
1469 LevelA3::Type x;
1470};
1471# elif defined(SECOND)
1472struct S3 {
1473 LevelB3::Type x;
1474};
1475#else
1476S3 s3;
1477// 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')}}
1478// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
1479#endif
1480
1481#if defined(FIRST)
1482struct TA4 { using Type = int; };
1483struct S4 {
1484 TA4::Type x;
1485};
1486# elif defined(SECOND)
1487struct TB4 { using Type = int; };
1488struct S4 {
1489 TB4::Type x;
1490};
1491#else
1492S4 s4;
1493// 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')}}
1494// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
1495#endif
1496
1497#if defined(FIRST)
1498struct T5 { using Type = int; };
1499struct S5 {
1500 T5::Type x;
1501};
1502# elif defined(SECOND)
1503namespace T5 { using Type = int; };
1504struct S5 {
1505 T5::Type x;
1506};
1507#else
1508S5 s5;
1509// 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')}}
1510// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
1511#endif
1512
1513#if defined(FIRST)
1514namespace N6 {using I = int;}
1515struct S6 {
1516 NestedNamespaceSpecifier::N6::I x;
1517};
1518# elif defined(SECOND)
1519using I = int;
1520struct S6 {
1521 ::NestedNamespaceSpecifier::I x;
1522};
1523#else
1524S6 s6;
1525// 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')}}
1526// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
1527#endif
1528
1529#if defined(FIRST)
1530template <class T, class U>
1531class S7 {
1532 typename T::type *x = {};
1533 int z = x->T::foo();
1534};
1535#elif defined(SECOND)
1536template <class T, class U>
1537class S7 {
1538 typename T::type *x = {};
1539 int z = x->U::foo();
1540};
1541#else
1542template <class T, class U>
1543using U7 = S7<T, U>;
1544// 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}}
1545// expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}}
1546#endif
1547
1548#if defined(FIRST)
1549template <class T>
1550class S8 {
1551 int x = T::template X<int>::value;
1552};
1553#elif defined(SECOND)
1554template <class T>
1555class S8 {
1556 int x = T::template Y<int>::value;
1557};
1558#else
1559template <class T>
1560using U8 = S8<T>;
1561// 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}}
1562// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
1563#endif
1564
1565#if defined(FIRST)
1566namespace N9 { using I = int; }
1567namespace O9 = N9;
1568struct S9 {
1569 O9::I x;
1570};
1571#elif defined(SECOND)
1572namespace N9 { using I = int; }
1573namespace P9 = N9;
1574struct S9 {
1575 P9::I x;
1576};
1577#else
1578S9 s9;
1579// 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')}}
1580// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
1581#endif
Richard Trieu96b41642017-07-01 02:00:05 +00001582
1583namespace N10 {
1584#if defined(FIRST)
1585inline namespace A { struct X {}; }
1586struct S10 {
1587 A::X x;
1588};
1589#elif defined(SECOND)
1590inline namespace B { struct X {}; }
1591struct S10 {
1592 B::X x;
1593};
1594#else
1595S10 s10;
1596// expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
1597// expected-note@first.h:* {{declaration of 'x' does not match}}
1598#endif
1599}
Richard Trieu73cf9242017-11-04 01:20:50 +00001600
1601#define DECLS \
1602 NS1::Type a; \
1603 NS1::NS2::Type b; \
1604 NS1::S c; \
1605 NS3::Type d;
1606
1607#if defined(FIRST) || defined(SECOND)
1608namespace NS1 {
1609 using Type = int;
1610 namespace NS2 {
1611 using Type = double;
1612 }
1613 struct S {};
Richard Trieuce81b192017-05-17 03:23:35 +00001614}
Richard Trieu73cf9242017-11-04 01:20:50 +00001615namespace NS3 = NS1;
1616#endif
1617
1618#if defined(FIRST) || defined(SECOND)
1619struct Valid1 {
1620 DECLS
1621};
1622#else
1623Valid1 v1;
1624#endif
1625
1626#if defined(FIRST) || defined(SECOND)
1627struct Invalid1 {
1628 DECLS
1629 ACCESS
1630};
1631#else
1632Invalid1 i1;
1633// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1634// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1635#endif
1636#undef DECLS
1637
1638#define DECLS \
1639 typename T::type *x = {}; \
1640 int y = x->T::foo(); \
1641 int z = U::template X<int>::value;
1642
1643#if defined(FIRST) || defined(SECOND)
1644template <class T, class U>
1645struct Valid2 {
1646 DECLS
1647};
1648#else
1649template <class T, class U>
1650using V2 = Valid2<T, U>;
1651#endif
1652
1653#if defined(FIRST) || defined(SECOND)
1654template <class T, class U>
1655struct Invalid2 {
1656 DECLS
1657 ACCESS
1658};
1659#else
1660template <class T, class U>
1661using I2 = Invalid2<T, U>;
1662// expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1663// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1664#endif
1665#undef DECLS
1666} // namespace NestedNamespaceSpecifier
Richard Trieuce81b192017-05-17 03:23:35 +00001667
Richard Trieu96b49622017-05-31 00:31:58 +00001668namespace TemplateSpecializationType {
1669#if defined(FIRST)
1670template <class T1> struct U1 {};
1671struct S1 {
1672 U1<int> u;
1673};
1674#elif defined(SECOND)
1675template <class T1, class T2> struct U1 {};
1676struct S1 {
1677 U1<int, int> u;
1678};
1679#else
1680S1 s1;
1681// expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}}
1682// expected-note@second.h:* {{declaration of 'u' does not match}}
1683#endif
1684
1685#if defined(FIRST)
1686template <class T1> struct U2 {};
1687struct S2 {
1688 U2<int> u;
1689};
1690#elif defined(SECOND)
1691template <class T1> struct V1 {};
1692struct S2 {
1693 V1<int> u;
1694};
1695#else
1696S2 s2;
1697// expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}}
1698// expected-note@second.h:* {{declaration of 'u' does not match}}
1699#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001700
1701#define DECLS \
1702 OneTemplateArg<int> x; \
1703 OneTemplateArg<double> y; \
1704 OneTemplateArg<char *> z; \
1705 TwoTemplateArgs<int, int> a; \
1706 TwoTemplateArgs<double, float> b; \
1707 TwoTemplateArgs<short *, char> c;
1708
1709#if defined(FIRST) || defined(SECOND)
1710template <class T> struct OneTemplateArg {};
1711template <class T, class U> struct TwoTemplateArgs {};
1712#endif
1713
1714#if defined(FIRST) || defined(SECOND)
1715struct Valid1 {
1716DECLS
1717};
1718#else
1719Valid1 v1;
1720#endif
1721
1722#if defined(FIRST) || defined(SECOND)
1723struct Invalid1 {
1724DECLS
1725ACCESS
1726};
1727#else
1728Invalid1 i1;
1729// expected-error@second.h:* {{'TemplateSpecializationType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1730// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1731#endif
1732#undef DECLS
1733} // namespace TemplateSpecializationType
Richard Trieu96b49622017-05-31 00:31:58 +00001734
Richard Trieu3b261bb72017-06-13 22:21:18 +00001735namespace TemplateArgument {
1736#if defined(FIRST)
1737template <class> struct U1{};
1738struct S1 {
1739 U1<int> x;
1740};
1741#elif defined(SECOND)
1742template <int> struct U1{};
1743struct S1 {
1744 U1<1> x;
1745};
1746#else
1747S1 s1;
1748// expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
1749// expected-note@second.h:* {{declaration of 'x' does not match}}
1750#endif
Richard Trieu1dcb4052017-06-14 01:28:00 +00001751
1752#if defined(FIRST)
1753template <int> struct U2{};
1754struct S2 {
1755 using T = U2<2>;
1756};
1757#elif defined(SECOND)
1758template <int> struct U2{};
1759struct S2 {
1760 using T = U2<(2)>;
1761};
1762#else
1763S2 s2;
1764// 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)>'}}
1765// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}}
1766#endif
1767
1768#if defined(FIRST)
1769template <int> struct U3{};
1770struct S3 {
1771 using T = U3<2>;
1772};
1773#elif defined(SECOND)
1774template <int> struct U3{};
1775struct S3 {
1776 using T = U3<1 + 1>;
1777};
1778#else
1779S3 s3;
1780// 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>'}}
1781// expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}}
1782#endif
1783
Richard Trieuee132d62017-06-14 03:17:26 +00001784#if defined(FIRST)
1785template<class> struct T4a {};
1786template <template <class> class T> struct U4 {};
1787struct S4 {
1788 U4<T4a> x;
1789};
1790#elif defined(SECOND)
1791template<class> struct T4b {};
1792template <template <class> class T> struct U4 {};
1793struct S4 {
1794 U4<T4b> x;
1795};
1796#else
1797S4 s4;
1798// expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}}
1799// expected-note@second.h:* {{declaration of 'x' does not match}}
1800#endif
Richard Trieu8844c522017-06-30 22:40:33 +00001801
1802#if defined(FIRST)
1803template <class T> struct U5 {};
1804struct S5 {
1805 U5<int> x;
1806};
1807#elif defined(SECOND)
1808template <class T> struct U5 {};
1809struct S5 {
1810 U5<short> x;
1811};
1812#else
1813S5 s5;
1814// expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}}
1815// expected-note@second.h:* {{declaration of 'x' does not match}}
1816#endif
1817
1818#if defined(FIRST)
1819template <class T> struct U6 {};
1820struct S6 {
1821 U6<int> x;
1822 U6<short> y;
1823};
1824#elif defined(SECOND)
1825template <class T> struct U6 {};
1826struct S6 {
1827 U6<short> y;
1828 U6<int> x;
1829};
1830#else
1831S6 s6;
1832// expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
1833// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
1834#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00001835
Richard Trieu7282d322018-04-25 00:31:15 +00001836#if defined(FIRST)
1837struct S7 {
1838 template<int> void run() {}
1839 template<> void run<1>() {}
1840};
1841#elif defined(SECOND)
1842struct S7 {
1843 template<int> void run() {}
1844 void run() {}
1845};
1846#else
1847S7 s7;
1848// 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}}
1849// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with template arguments}}
1850#endif
1851
1852#if defined(FIRST)
1853struct S8 {
1854 static int a, b;
1855 template<int&> void run() {}
1856 template<int&, int&> void run() {}
1857 template<> void run<a>() {}
1858};
1859#elif defined(SECOND)
1860struct S8 {
1861 static int a, b;
1862 template<int&> void run() {}
1863 template<int&, int&> void run() {}
1864 template<> void run<a, b>() {}
1865};
1866#else
1867S8 s8;
1868// 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}}
1869// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 1 template argument}}
1870#endif
1871
1872#if defined(FIRST)
1873struct S9 {
1874 static int a, b;
1875 template<int&> void run() {}
1876 template<> void run<a>() {}
1877};
1878#elif defined(SECOND)
1879struct S9 {
1880 static int a, b;
1881 template<int&> void run() {}
1882 template<> void run<b>() {}
1883};
1884#else
1885S9 s9;
1886// 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}}
1887// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 1st template argument}}
1888#endif
1889
1890#if defined(FIRST)
1891struct S10 {
1892 static int a, b;
1893 template<int, int&...> void run() {}
1894 template<> void run<1, a>() {}
1895};
1896#elif defined(SECOND)
1897struct S10 {
1898 static int a, b;
1899 template<int, int&...> void run() {}
1900 template<> void run<1, b>() {}
1901};
1902#else
1903S10 s10;
1904// 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}}
1905// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 2nd template argument}}
1906#endif
1907
1908#if defined(FIRST)
1909struct S11 {
1910 static int a, b;
1911 template<int, int&...> void run() {}
1912 template<> void run<1, a>() {}
1913};
1914#elif defined(SECOND)
1915struct S11 {
1916 static int a, b;
1917 template<int, int&...> void run() {}
1918 template<> void run<1, a, a>() {}
1919};
1920#else
1921S11 s11;
1922// 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}}
1923// expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 2 template arguments}}
1924#endif
1925
Richard Trieu73cf9242017-11-04 01:20:50 +00001926#define DECLS \
1927 OneClass<int> a; \
1928 OneInt<1> b; \
1929 using c = OneClass<float>; \
1930 using d = OneInt<2>; \
1931 using e = OneInt<2 + 2>; \
1932 OneTemplateClass<OneClass> f; \
Richard Trieu7282d322018-04-25 00:31:15 +00001933 OneTemplateInt<OneInt> g; \
1934 static int i1, i2; \
1935 template <int &> \
1936 void Function() {} \
1937 template <int &, int &> \
1938 void Function() {} \
1939 template <> \
1940 void Function<i1>() {} \
1941 template <> \
1942 void Function<i2>() {} \
1943 template <> \
1944 void Function<i1, i2>() {} \
1945 template <> \
1946 void Function<i2, i1>() {}
Richard Trieu73cf9242017-11-04 01:20:50 +00001947
1948#if defined(FIRST) || defined(SECOND)
1949template <class> struct OneClass{};
1950template <int> struct OneInt{};
1951template <template <class> class> struct OneTemplateClass{};
1952template <template <int> class> struct OneTemplateInt{};
1953#endif
1954
1955#if defined(FIRST) || defined(SECOND)
1956struct Valid1 {
1957DECLS
1958};
1959#else
1960Valid1 v1;
1961#endif
1962
1963#if defined(FIRST) || defined(SECOND)
1964struct Invalid1 {
1965DECLS
1966ACCESS
1967};
1968#else
1969Invalid1 i1;
1970// expected-error@second.h:* {{'TemplateArgument::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1971// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1972#endif
1973#undef DECLS
1974} // namespace TemplateArgument
Richard Trieuee132d62017-06-14 03:17:26 +00001975
Richard Trieud9201d02017-06-15 01:35:06 +00001976namespace TemplateTypeParmType {
1977#if defined(FIRST)
1978template <class T1, class T2>
1979struct S1 {
1980 T1 x;
1981};
1982#elif defined(SECOND)
1983template <class T1, class T2>
1984struct S1 {
1985 T2 x;
1986};
1987#else
1988using TemplateTypeParmType::S1;
1989// expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}}
1990// expected-note@second.h:* {{declaration of 'x' does not match}}
1991#endif
1992
1993#if defined(FIRST)
1994template <int ...Ts>
1995struct U2 {};
1996template <int T, int U>
1997class S2 {
1998 typedef U2<U, T> type;
1999 type x;
2000};
2001#elif defined(SECOND)
2002template <int ...Ts>
2003struct U2 {};
2004template <int T, int U>
2005class S2 {
2006 typedef U2<T, U> type;
2007 type x;
2008};
2009#else
2010using TemplateTypeParmType::S2;
2011// expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
2012// expected-note@second.h:* {{declaration of 'x' does not match}}
2013// expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
2014// expected-note@second.h:* {{declaration of 'type' does not match}}
2015#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002016
2017#define DECLS \
2018 T t; \
2019 U u; \
2020 ParameterPack<T> a; \
2021 ParameterPack<T, U> b; \
2022 ParameterPack<U> c; \
2023 ParameterPack<U, T> d;
2024
2025#if defined(FIRST) || defined(SECOND)
2026template <class ...Ts> struct ParameterPack {};
2027#endif
2028
2029#if defined(FIRST) || defined(SECOND)
2030template <class T, class U>
2031struct Valid1 {
2032 DECLS
2033};
2034#else
2035using TemplateTypeParmType::Valid1;
2036#endif
2037
2038#if defined(FIRST) || defined(SECOND)
2039template <class T, class U>
2040struct Invalid1 {
2041 DECLS
2042 ACCESS
2043};
2044#else
2045using TemplateTypeParmType::Invalid1;
2046// expected-error@second.h:* {{'TemplateTypeParmType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2047// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2048#endif
2049#undef DECLS
2050} // namespace TemplateTypeParmType
Richard Trieu3b261bb72017-06-13 22:21:18 +00002051
Richard Trieu6e13ff32017-06-16 02:44:29 +00002052namespace VarDecl {
2053#if defined(FIRST)
2054struct S1 {
2055 static int x;
2056 static int y;
2057};
2058#elif defined(SECOND)
2059struct S1 {
2060 static int y;
2061 static int x;
2062};
2063#else
2064S1 s1;
2065// 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'}}
2066// expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}}
2067#endif
2068
2069#if defined(FIRST)
2070struct S2 {
2071 static int x;
2072};
2073#elif defined(SECOND)
2074using I = int;
2075struct S2 {
2076 static I x;
2077};
2078#else
2079S2 s2;
2080// 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')}}
2081// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}}
2082#endif
2083
2084#if defined(FIRST)
2085struct S3 {
2086 static const int x = 1;
2087};
2088#elif defined(SECOND)
2089struct S3 {
2090 static const int x;
2091};
2092#else
2093S3 s3;
2094// 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}}
2095// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}}
2096#endif
2097
2098#if defined(FIRST)
2099struct S4 {
2100 static const int x = 1;
2101};
2102#elif defined(SECOND)
2103struct S4 {
2104 static const int x = 2;
2105};
2106#else
2107S4 s4;
2108// 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}}
2109// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}}
2110#endif
2111
2112#if defined(FIRST)
2113struct S5 {
2114 static const int x = 1;
2115};
2116#elif defined(SECOND)
2117struct S5 {
2118 static constexpr int x = 1;
2119};
2120#else
2121S5 s5;
2122// 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}}
2123// expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}}
2124#endif
2125
2126#if defined(FIRST)
2127struct S6 {
2128 static const int x = 1;
2129};
2130#elif defined(SECOND)
2131struct S6 {
2132 static const int y = 1;
2133};
2134#else
2135S6 s6;
2136// expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}}
2137// expected-note@second.h:* {{definition has no member 'x'}}
2138#endif
2139
2140#if defined(FIRST)
2141struct S7 {
2142 static const int x = 1;
2143};
2144#elif defined(SECOND)
2145struct S7 {
2146 static const unsigned x = 1;
2147};
2148#else
2149S7 s7;
2150// expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}}
2151// expected-note@second.h:* {{declaration of 'x' does not match}}
2152#endif
2153
2154#if defined(FIRST)
2155struct S8 {
2156public:
2157 static const int x = 1;
2158};
2159#elif defined(SECOND)
2160struct S8 {
2161 static const int x = 1;
2162public:
2163};
2164#else
2165S8 s8;
2166// expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}}
2167// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2168#endif
2169
2170#if defined(FIRST)
2171struct S9 {
2172 static const int x = 1;
2173};
2174#elif defined(SECOND)
2175struct S9 {
2176 static int x;
2177};
2178#else
2179S9 s9;
2180// expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}}
2181// expected-note@second.h:* {{declaration of 'x' does not match}}
2182#endif
2183
Richard Trieu73cf9242017-11-04 01:20:50 +00002184#define DECLS \
2185 static int a; \
2186 static I b; \
2187 static const int c = 1; \
2188 static constexpr int d = 5;
2189
2190#if defined(FIRST) || defined(SECOND)
2191using I = int;
Richard Trieu6e13ff32017-06-16 02:44:29 +00002192#endif
2193
Richard Trieu73cf9242017-11-04 01:20:50 +00002194#if defined(FIRST) || defined(SECOND)
2195struct Valid1 {
2196 DECLS
Richard Trieu6e13ff32017-06-16 02:44:29 +00002197};
Richard Trieu6e13ff32017-06-16 02:44:29 +00002198#else
Richard Trieu73cf9242017-11-04 01:20:50 +00002199Valid1 v1;
Richard Trieu6e13ff32017-06-16 02:44:29 +00002200#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002201
2202#if defined(FIRST) || defined(SECOND)
2203struct Invalid1 {
2204 DECLS
2205 ACCESS
2206};
2207#else
2208Invalid1 i1;
2209// expected-error@second.h:* {{'VarDecl::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2210// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2211#endif
2212#undef DECLS
2213} // namespace VarDecl
Richard Trieu6e13ff32017-06-16 02:44:29 +00002214
Richard Trieuac6a1b62017-07-08 02:04:42 +00002215namespace Friend {
2216#if defined(FIRST)
2217struct T1 {};
2218struct S1 {
2219 friend class T1;
2220};
2221#elif defined(SECOND)
2222struct T1 {};
2223struct S1 {
2224 friend T1;
2225};
2226#else
2227S1 s1;
2228// expected-error@second.h:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T1'}}
2229// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T1'}}
2230#endif
2231
2232#if defined(FIRST)
2233struct T2 {};
2234struct S2 {
2235 friend class T2;
2236};
2237#elif defined(SECOND)
2238struct T2 {};
2239struct S2 {
2240 friend struct T2;
2241};
2242#else
2243S2 s2;
2244// expected-error@second.h:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}}
2245// expected-note@first.h:* {{but in 'FirstModule' found friend 'class T2'}}
2246#endif
2247
2248#if defined(FIRST)
Richard Trieuac6a1b62017-07-08 02:04:42 +00002249struct T4 {};
2250struct S4 {
2251 friend T4;
2252};
2253#elif defined(SECOND)
2254struct S4 {
2255 friend void T4();
2256};
2257#else
2258S4 s4;
2259// expected-error@second.h:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}}
2260// expected-note@first.h:* {{but in 'FirstModule' found friend class}}
2261#endif
2262
2263#if defined(FIRST)
2264struct S5 {
2265 friend void T5a();
2266};
2267#elif defined(SECOND)
2268struct S5 {
2269 friend void T5b();
2270};
2271#else
2272S5 s5;
2273// expected-error@second.h:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}}
2274// expected-note@first.h:* {{but in 'FirstModule' found friend function 'T5a'}}
2275#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002276
2277#define DECLS \
2278 friend class FriendA; \
2279 friend struct FriendB; \
2280 friend FriendC; \
Richard Trieu73cf9242017-11-04 01:20:50 +00002281 friend void Function();
2282
2283#if defined(FIRST) || defined(SECOND)
2284class FriendA {};
2285class FriendB {};
2286class FriendC {};
Richard Trieu73cf9242017-11-04 01:20:50 +00002287#endif
2288
2289#if defined(FIRST) || defined(SECOND)
2290struct Valid1 {
2291 DECLS
2292};
2293#else
2294Valid1 v1;
2295#endif
2296
2297#if defined(FIRST) || defined(SECOND)
2298struct Invalid1 {
2299 DECLS
2300 ACCESS
2301};
2302#else
2303Invalid1 i1;
2304// expected-error@second.h:* {{'Friend::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2305// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2306#endif
2307#undef DECLS
2308} // namespace Friend
Richard Trieu498117b2017-08-23 02:43:59 +00002309
2310namespace TemplateParameters {
2311#if defined(FIRST)
2312template <class A>
2313struct S1 {};
2314#elif defined(SECOND)
2315template <class B>
2316struct S1 {};
2317#else
2318using TemplateParameters::S1;
2319// expected-error@second.h:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}}
2320// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2321#endif
2322
2323#if defined(FIRST)
2324template <class A = double>
2325struct S2 {};
2326#elif defined(SECOND)
2327template <class A = int>
2328struct S2 {};
2329#else
2330using TemplateParameters::S2;
2331// 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}}
2332// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2333#endif
2334
2335#if defined(FIRST)
2336template <class A = int>
2337struct S3 {};
2338#elif defined(SECOND)
2339template <class A>
2340struct S3 {};
2341#else
2342using TemplateParameters::S3;
2343// 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}}
2344// expected-note@first.h:* {{but in 'FirstModule' found template parameter with default argument}}
2345#endif
2346
2347#if defined(FIRST)
2348template <int A>
2349struct S4 {};
2350#elif defined(SECOND)
2351template <int A = 2>
2352struct S4 {};
2353#else
2354using TemplateParameters::S4;
2355// 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}}
2356// expected-note@first.h:* {{but in 'FirstModule' found template parameter with no default argument}}
2357#endif
2358
2359#if defined(FIRST)
2360template <int> class S5_first {};
2361template <template<int> class A = S5_first>
2362struct S5 {};
2363#elif defined(SECOND)
2364template <int> class S5_second {};
2365template <template<int> class A = S5_second>
2366struct S5 {};
2367#else
2368using TemplateParameters::S5;
2369// 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}}
2370// expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2371#endif
2372
2373#if defined(FIRST)
2374template <class A>
2375struct S6 {};
2376#elif defined(SECOND)
2377template <class>
2378struct S6 {};
2379#else
2380using TemplateParameters::S6;
2381// expected-error@second.h:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}}
2382// expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2383#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002384
2385#define DECLS
2386
2387#if defined(FIRST) || defined(SECOND)
2388template <class> class DefaultArg;
2389#endif
2390
2391#if defined(FIRST) || defined(SECOND)
2392template <int, class, template <class> class,
2393 int A, class B, template <int> class C,
2394 int D = 1, class E = int, template <class F> class = DefaultArg>
2395struct Valid1 {
2396 DECLS
2397};
2398#else
2399using TemplateParameters::Valid1;
2400#endif
2401
2402#if defined(FIRST) || defined(SECOND)
2403template <int, class, template <class> class,
2404 int A, class B, template <int> class C,
2405 int D = 1, class E = int, template <class F> class = DefaultArg>
2406struct Invalid1 {
2407 DECLS
2408 ACCESS
2409};
2410#else
2411using TemplateParameters::Invalid1;
2412// expected-error@second.h:* {{'TemplateParameters::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2413// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2414#endif
2415#undef DECLS
Richard Trieu498117b2017-08-23 02:43:59 +00002416} // namespace TemplateParameters
2417
Richard Trieue13eabe2017-09-30 02:19:17 +00002418namespace BaseClass {
2419#if defined(FIRST)
2420struct B1 {};
2421struct S1 : B1 {};
2422#elif defined(SECOND)
2423struct S1 {};
2424#else
2425S1 s1;
2426// expected-error@second.h:* {{'BaseClass::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 base classes}}
2427// expected-note@first.h:* {{but in 'FirstModule' found 1 base class}}
2428#endif
2429
2430#if defined(FIRST)
2431struct S2 {};
2432#elif defined(SECOND)
2433struct B2 {};
2434struct S2 : virtual B2 {};
2435#else
2436S2 s2;
2437// expected-error@second.h:* {{'BaseClass::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 base class}}
2438// expected-note@first.h:* {{but in 'FirstModule' found 0 base classes}}
2439#endif
2440
2441#if defined(FIRST)
2442struct B3a {};
2443struct S3 : B3a {};
2444#elif defined(SECOND)
2445struct B3b {};
2446struct S3 : virtual B3b {};
2447#else
2448S3 s3;
2449// expected-error@second.h:* {{'BaseClass::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2450// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2451#endif
2452
2453#if defined(FIRST)
2454struct B4a {};
2455struct S4 : B4a {};
2456#elif defined(SECOND)
2457struct B4b {};
2458struct S4 : B4b {};
2459#else
2460S4 s4;
2461// 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'}}
2462// expected-note@first.h:* {{but in 'FirstModule' found 1st base class with different type 'BaseClass::B4a'}}
2463#endif
2464
2465#if defined(FIRST)
2466struct B5a {};
2467struct S5 : virtual B5a {};
2468#elif defined(SECOND)
2469struct B5a {};
2470struct S5 : B5a {};
2471#else
2472S5 s5;
2473// expected-error@second.h:* {{'BaseClass::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 virtual base classes}}
2474// expected-note@first.h:* {{but in 'FirstModule' found 1 virtual base class}}
2475#endif
2476
2477#if defined(FIRST)
2478struct B6a {};
2479struct S6 : B6a {};
2480#elif defined(SECOND)
2481struct B6a {};
2482struct S6 : virtual B6a {};
2483#else
2484S6 s6;
2485// expected-error@second.h:* {{'BaseClass::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2486// expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2487#endif
2488
2489#if defined(FIRST)
2490struct B7a {};
2491struct S7 : protected B7a {};
2492#elif defined(SECOND)
2493struct B7a {};
2494struct S7 : B7a {};
2495#else
2496S7 s7;
2497// 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}}
2498// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B7a' with protected access specifier}}
2499#endif
2500
2501#if defined(FIRST)
2502struct B8a {};
2503struct S8 : public B8a {};
2504#elif defined(SECOND)
2505struct B8a {};
2506struct S8 : private B8a {};
2507#else
2508S8 s8;
2509// 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}}
2510// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B8a' with public access specifier}}
2511#endif
2512
2513#if defined(FIRST)
2514struct B9a {};
2515struct S9 : private B9a {};
2516#elif defined(SECOND)
2517struct B9a {};
2518struct S9 : public B9a {};
2519#else
2520S9 s9;
2521// 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}}
2522// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B9a' with private access specifier}}
2523#endif
2524
2525#if defined(FIRST)
2526struct B10a {};
2527struct S10 : B10a {};
2528#elif defined(SECOND)
2529struct B10a {};
2530struct S10 : protected B10a {};
2531#else
2532S10 s10;
2533// 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}}
2534// expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'BaseClass::B10a' with no access specifier}}
2535#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00002536
2537#define DECLS
2538
2539#if defined(FIRST) || defined(SECOND)
2540struct Base1 {};
2541struct Base2 {};
2542struct Base3 {};
2543struct Base4 {};
2544struct Base5 {};
2545#endif
2546
2547#if defined(FIRST) || defined(SECOND)
2548struct Valid1 :
2549 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2550
2551 DECLS
2552};
2553#else
2554Valid1 v1;
2555#endif
2556
2557#if defined(FIRST) || defined(SECOND)
2558struct Invalid1 :
2559 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2560
2561 DECLS
2562 ACCESS
2563};
2564#else
2565Invalid1 i1;
2566// expected-error@second.h:* {{'BaseClass::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2567// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2568#endif
2569#undef DECLS
Richard Trieue13eabe2017-09-30 02:19:17 +00002570} // namespace BaseClass
2571
Richard Trieu15970af2018-04-13 22:34:43 +00002572namespace PointersAndReferences {
2573#if defined(FIRST) || defined(SECOND)
2574template<typename> struct Wrapper{};
2575#endif
2576
2577#if defined(FIRST)
2578struct S1 {
2579 Wrapper<int*> x;
2580};
2581#elif defined(SECOND)
2582struct S1 {
2583 Wrapper<float*> x;
2584};
2585#else
2586S1 s1;
2587// expected-error@first.h:* {{PointersAndReferences::S1::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S1' in module 'SecondModule'}}
2588// expected-note@second.h:* {{declaration of 'x' does not match}}
2589#endif
2590
2591#if defined(FIRST)
2592struct S2 {
2593 Wrapper<int &&> x;
2594};
2595#elif defined(SECOND)
2596struct S2 {
2597 Wrapper<float &&> x;
2598};
2599#else
2600S2 s2;
2601// expected-error@first.h:* {{PointersAndReferences::S2::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S2' in module 'SecondModule'}}
2602// expected-note@second.h:* {{declaration of 'x' does not match}}
2603#endif
2604
2605#if defined(FIRST)
2606struct S3 {
2607 Wrapper<int *> x;
2608};
2609#elif defined(SECOND)
2610struct S3 {
2611 Wrapper<float *> x;
2612};
2613#else
2614S3 s3;
2615// expected-error@first.h:* {{PointersAndReferences::S3::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S3' in module 'SecondModule'}}
2616// expected-note@second.h:* {{declaration of 'x' does not match}}
2617#endif
2618
2619#if defined(FIRST)
2620struct S4 {
2621 Wrapper<int &> x;
2622};
2623#elif defined(SECOND)
2624struct S4 {
2625 Wrapper<float &> x;
2626};
2627#else
2628S4 s4;
2629// expected-error@first.h:* {{PointersAndReferences::S4::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S4' in module 'SecondModule'}}
2630// expected-note@second.h:* {{declaration of 'x' does not match}}
2631#endif
2632
2633#if defined(FIRST)
2634struct S5 {
2635 Wrapper<S5 *> x;
2636};
2637#elif defined(SECOND)
2638struct S5 {
2639 Wrapper<const S5 *> x;
2640};
2641#else
2642S5 s5;
2643// expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 'SecondModule' is not present in definition of 'PointersAndReferences::S5' in module 'FirstModule'}}
2644// expected-note@first.h:* {{declaration of 'x' does not match}}
2645#endif
2646
2647#if defined(FIRST)
2648struct S6 {
2649 Wrapper<int &> x;
2650};
2651#elif defined(SECOND)
2652struct S6 {
2653 Wrapper<const int &> x;
2654};
2655#else
2656S6 s6;
2657// expected-error@first.h:* {{PointersAndReferences::S6::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S6' in module 'SecondModule'}}
2658// expected-note@second.h:* {{declaration of 'x' does not match}}
2659#endif
2660
2661#define DECLS \
2662 Wrapper<int *> x1; \
2663 Wrapper<float *> x2; \
2664 Wrapper<const float *> x3; \
2665 Wrapper<int &> x4; \
2666 Wrapper<int &&> x5; \
2667 Wrapper<const int &> x6; \
2668 Wrapper<S1 *> x7; \
2669 Wrapper<S1 &> x8; \
2670 Wrapper<S1 &&> x9;
2671
2672#if defined(FIRST) || defined(SECOND)
2673struct Valid1 {
2674 DECLS
2675};
2676#else
2677Valid1 v1;
2678#endif
2679
2680#if defined(FIRST) || defined(SECOND)
2681struct Invalid1 {
2682 DECLS
2683 ACCESS
2684};
2685#else
2686Invalid1 i1;
2687// expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2688// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2689#endif
2690#undef DECLS
2691} // namespace PointersAndReferences
2692
Richard Trieu9359e8f2018-05-30 01:12:26 +00002693namespace FunctionTemplate {
2694#if defined(FIRST)
2695struct S1 {
2696 template <int, int> void foo();
2697};
2698#elif defined(SECOND)
2699struct S1 {
2700 template <int> void foo();
2701};
2702#else
2703S1 s1;
2704// expected-error@first.h:* {{'FunctionTemplate::S1::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S1' in module 'SecondModule'}}
2705// expected-note@second.h:* {{declaration of 'foo' does not match}}
2706#endif
2707
2708#if defined(FIRST)
2709struct S2 {
2710 template <char> void foo();
2711};
2712#elif defined(SECOND)
2713struct S2 {
2714 template <int> void foo();
2715};
2716#else
2717S2 s2;
2718// expected-error@first.h:* {{'FunctionTemplate::S2::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S2' in module 'SecondModule'}}
2719// expected-note@second.h:* {{declaration of 'foo' does not match}}
2720#endif
2721
2722#if defined(FIRST)
2723struct S3 {
2724 template <int x> void foo();
2725};
2726#elif defined(SECOND)
2727struct S3 {
2728 template <int y> void foo();
2729};
2730#else
2731S3 s3;
2732// 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'}}
2733// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2734#endif
2735
2736#if defined(FIRST)
2737struct S4 {
2738 template <int x> void foo();
2739};
2740#elif defined(SECOND)
2741struct S4 {
2742 template <int x> void bar();
2743};
2744#else
2745S4 s4;
2746// expected-error@first.h:* {{'FunctionTemplate::S4::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S4' in module 'SecondModule'}}
2747// expected-note@second.h:* {{definition has no member 'foo'}}
2748#endif
2749
2750#if defined(FIRST)
2751struct S5 {
2752 template <int x> void foo();
2753};
2754#elif defined(SECOND)
2755struct S5 {
2756 public:
2757 template <int x> void foo();
2758};
2759#else
2760S5 s5;
2761// expected-error@second.h:* {{'FunctionTemplate::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
2762// expected-note@first.h:* {{but in 'FirstModule' found function template}}
2763#endif
2764
2765#if defined(FIRST)
2766struct S6 {
2767 template <typename x = int> void foo();
2768};
2769#elif defined(SECOND)
2770struct S6 {
2771 template <typename x> void foo();
2772};
2773#else
2774S6 s6;
2775// 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}}
2776// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2777#endif
2778
2779#if defined(FIRST)
2780struct S7 {
2781 template <typename x = void> void foo();
2782};
2783#elif defined(SECOND)
2784struct S7 {
2785 template <typename x = int> void foo();
2786};
2787#else
2788S7 s7;
2789// 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'}}
2790// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'void'}}
2791#endif
2792
2793#if defined(FIRST)
2794template <int>
2795struct U8 {};
2796struct S8 {
2797 template <template<int> class x = U8> void foo();
2798};
2799#elif defined(SECOND)
2800template <int>
2801struct T8 {};
2802struct S8{
2803 template <template<int> class x = T8> void foo();
2804};
2805#else
2806S8 s8;
2807// 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'}}
2808// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'U8'}}
2809#endif
2810
2811#if defined(FIRST)
2812template <int>
2813struct U9 {};
2814struct S9 { S9();
2815 template <template<int> class x = U9> void foo();
2816};
2817#elif defined(SECOND)
2818struct S9 { S9();
2819 template <template<int> class x> void foo();
2820};
2821#else
2822S9 s9;
2823// 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}}
2824// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2825#endif
2826
2827#if defined(FIRST)
2828struct S10 {
2829 template <template<int> class x> void foo();
2830 template <template<typename> class x> void foo();
2831};
2832#elif defined(SECOND)
2833struct S10 {
2834 template <template<typename> class x> void foo();
2835 template <template<int> class x> void foo();
2836};
2837#else
2838S10 s10;
2839// 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}}
2840// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
2841#endif
2842
2843#if defined(FIRST)
2844struct S11 {
2845 template <template<int> class x> void foo();
2846};
2847#elif defined(SECOND)
2848struct S11 {
2849 template <template<int> class> void foo();
2850};
2851#else
2852S11 s11;
2853// 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}}
2854// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2855#endif
2856
2857#if defined(FIRST)
2858struct S12 {
2859 template <class> void foo();
2860 template <class, class> void foo();
2861};
2862#elif defined(SECOND)
2863struct S12 {
2864 template <class, class> void foo();
2865 template <class> void foo();
2866};
2867#else
2868S12 s12;
2869// 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}}
2870// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1 template parameter}}
2871#endif
2872
2873#if defined(FIRST)
2874struct S13 {
2875 template <class = int> void foo();
2876};
2877#elif defined(SECOND)
2878struct S13 {
2879 template <class = void> void foo();
2880};
2881#else
2882S13 s13;
2883// 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'}}
2884// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'int'}}
2885#endif
2886
2887#if defined(FIRST)
2888struct S14 {
2889 template <class = void> void foo();
2890};
2891#elif defined(SECOND)
2892struct S14 {
2893 template <class> void foo();
2894};
2895#else
2896S14 s14;
2897// 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}}
2898// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
2899#endif
2900
2901#if defined(FIRST)
2902struct S15 {
2903 template <class> void foo();
2904};
2905#elif defined(SECOND)
2906struct S15 {
2907 template <class = void> void foo();
2908};
2909#else
2910S15 s15;
2911// 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}}
2912// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
2913#endif
2914
2915#if defined(FIRST)
2916struct S16 {
2917 template <short> void foo();
2918};
2919#elif defined(SECOND)
2920struct S16 {
2921 template <short = 1> void foo();
2922};
2923#else
2924S16 s16;
2925// 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}}
2926// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
2927#endif
2928
2929#if defined(FIRST)
2930struct S17 {
2931 template <short = 2> void foo();
2932};
2933#elif defined(SECOND)
2934struct S17 {
2935 template <short = 1 + 1> void foo();
2936};
2937#else
2938S17 s17;
2939// 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}}
2940// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 2}}
2941#endif
2942
2943#if defined(FIRST)
2944struct S18 {
2945 template <short> void foo();
2946 template <int> void foo();
2947};
2948#elif defined(SECOND)
2949struct S18 {
2950 template <int> void foo();
2951 template <short> void foo();
2952};
2953#else
2954S18 s18;
2955// 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}}
2956// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
2957#endif
2958
2959#if defined(FIRST)
2960struct S19 {
2961 template <short> void foo();
2962 template <short...> void foo();
2963};
2964#elif defined(SECOND)
2965struct S19 {
2966 template <short...> void foo();
2967 template <short> void foo();
2968};
2969#else
2970S19 s19;
2971// 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}}
2972// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
2973#endif
2974
2975#if defined(FIRST)
2976struct S20 {
2977 template <class> void foo();
2978 template <class...> void foo();
2979};
2980#elif defined(SECOND)
2981struct S20 {
2982 template <class...> void foo();
2983 template <class> void foo();
2984};
2985#else
2986S20 s20;
2987// 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}}
2988// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
2989#endif
2990
2991#if defined(FIRST)
2992struct S21 {
2993 template <template<class> class...> void foo();
2994 template <template<class> class> void foo();
2995};
2996#elif defined(SECOND)
2997struct S21 {
2998 template <template<class> class> void foo();
2999 template <template<class> class...> void foo();
3000};
3001#else
3002S21 s21;
3003// 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}}
3004// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter being a template parameter pack}}
3005#endif
3006
3007#if defined(FIRST)
3008struct S22 {
3009 template <template<class> class> void foo();
3010 template <class> void foo();
3011 template <int> void foo();
3012};
3013#elif defined(SECOND)
3014struct S22 {
3015 template <class> void foo();
3016 template <int> void foo();
3017 template <template<class> class> void foo();
3018};
3019#else
3020S22 s22;
3021// 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}}
3022// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a template template parameter}}
3023#endif
3024
3025#if defined(FIRST)
3026struct S23 {
3027 template <class> void foo();
3028 template <int> void foo();
3029 template <template<class> class> void foo();
3030};
3031#elif defined(SECOND)
3032struct S23 {
3033 template <int> void foo();
3034 template <template<class> class> void foo();
3035 template <class> void foo();
3036};
3037#else
3038S23 s23;
3039// 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}}
3040// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a type template parameter}}
3041#endif
3042
3043#if defined(FIRST)
3044struct S24 {
3045 template <int> void foo();
3046 template <template<class> class> void foo();
3047 template <class> void foo();
3048};
3049#elif defined(SECOND)
3050struct S24 {
3051 template <template<class> class> void foo();
3052 template <class> void foo();
3053 template <int> void foo();
3054};
3055#else
3056S24 s24;
3057// 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}}
3058// expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a non-type template parameter}}
3059#endif
3060
3061#if defined(FIRST)
3062struct S25 {
3063 template <int> void foo();
3064};
3065#elif defined(SECOND)
3066struct S25 {
3067 public:
3068 template <int> void foo();
3069};
3070#else
3071S25 s25;
3072// expected-error@second.h:* {{'FunctionTemplate::S25' 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 function template}}
3074#endif
3075
3076#define DECLS \
3077 template <int> \
3078 void nontype1(); \
3079 template <int x> \
3080 void nontype2(); \
3081 template <int, int> \
3082 void nontype3(); \
3083 template <int x = 5> \
3084 void nontype4(); \
3085 template <int... x> \
3086 void nontype5(); \
3087 \
3088 template <class> \
3089 void type1(); \
3090 template <class x> \
3091 void type2(); \
3092 template <class, class> \
3093 void type3(); \
3094 template <class x = int> \
3095 void type4(); \
3096 template <class... x> \
3097 void type5(); \
3098 \
3099 template <template <int> class> \
3100 void template1(); \
3101 template <template <int> class x> \
3102 void template2(); \
3103 template <template <int> class, template <int> class> \
3104 void template3(); \
3105 template <template <int> class x = U> \
3106 void template4(); \
3107 template <template <int> class... x> \
3108 void template5();
3109
3110#if defined(FIRST) || defined(SECOND)
3111template<int>
3112struct U {};
3113struct Valid1 {
3114 DECLS
3115};
3116#else
3117Valid1 v1;
3118#endif
3119
3120#if defined(FIRST) || defined(SECOND)
3121struct Invalid1 {
3122 DECLS
3123 ACCESS
3124};
3125#else
3126Invalid1 i1;
3127// expected-error@second.h:* {{'FunctionTemplate::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3128// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3129#endif
3130#undef DECLS
3131}
Richard Trieu73cf9242017-11-04 01:20:50 +00003132
Richard Trieuab4d7302018-07-25 22:52:05 +00003133namespace Enums {
3134#if defined(FIRST)
3135enum E1 { x11 };
3136#elif defined(SECOND)
3137enum E1 {};
3138#else
3139E1 e1;
3140// expected-error@first.h:* {{'Enums::x11' from module 'FirstModule' is not present in definition of 'Enums::E1' in module 'SecondModule'}}
3141// expected-note@second.h:* {{definition has no member 'x11'}}
3142#endif
3143
3144#if defined(FIRST)
3145enum E2 {};
3146#elif defined(SECOND)
3147enum E2 { x21 };
3148#else
3149E2 e2;
3150// expected-error@second.h:* {{'Enums::E2' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 1 element}}
3151// expected-note@first.h:* {{but in 'FirstModule' found enum with 0 elements}}
3152#endif
3153
3154#if defined(FIRST)
3155enum E3 { x31 };
3156#elif defined(SECOND)
3157enum E3 { x32 };
3158#else
3159E3 e3;
3160// expected-error@first.h:* {{'Enums::x31' from module 'FirstModule' is not present in definition of 'Enums::E3' in module 'SecondModule'}}
3161// expected-note@second.h:* {{definition has no member 'x31'}}
3162#endif
3163
3164#if defined(FIRST)
3165enum E4 { x41 };
3166#elif defined(SECOND)
3167enum E4 { x41, x42 };
3168#else
3169E4 e4;
3170// expected-error@second.h:* {{'Enums::E4' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 2 elements}}
3171// expected-note@first.h:* {{but in 'FirstModule' found enum with 1 element}}
3172#endif
3173
3174#if defined(FIRST)
3175enum E5 { x51, x52 };
3176#elif defined(SECOND)
3177enum E5 { x51 };
3178#else
3179E5 e5;
3180// expected-error@first.h:* {{'Enums::x52' from module 'FirstModule' is not present in definition of 'Enums::E5' in module 'SecondModule'}}
3181// expected-note@second.h:* {{definition has no member 'x52'}}
3182#endif
3183
3184#if defined(FIRST)
3185enum E6 { x61, x62 };
3186#elif defined(SECOND)
3187enum E6 { x62, x61 };
3188#else
3189E6 e6;
3190// expected-error@second.h:* {{'Enums::E6' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element has name 'x62'}}
3191// expected-note@first.h:* {{but in 'FirstModule' found 1st element has name 'x61'}}
3192#endif
3193
3194#if defined(FIRST)
3195enum E7 { x71 = 0 };
3196#elif defined(SECOND)
3197enum E7 { x71 };
3198#else
3199E7 e7;
3200// expected-error@second.h:* {{'Enums::E7' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x71' has an initilizer}}
3201// expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x71' does not have an initializer}}
3202#endif
3203
3204#if defined(FIRST)
3205enum E8 { x81 };
3206#elif defined(SECOND)
3207enum E8 { x81 = 0 };
3208#else
3209E8 e8;
3210// expected-error@second.h:* {{'Enums::E8' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x81' does not have an initilizer}}
3211// expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x81' has an initializer}}
3212#endif
3213
3214#if defined(FIRST)
3215enum E9 { x91 = 0, x92 = 1 };
3216#elif defined(SECOND)
3217enum E9 { x91 = 0, x92 = 2 - 1 };
3218#else
3219E9 e9;
3220// expected-error@second.h:* {{'Enums::E9' has different definitions in different modules; definition in module 'SecondModule' first difference is 2nd element 'x92' has an initializer}}
3221// expected-note@first.h:* {{but in 'FirstModule' found 2nd element 'x92' has different initializer}}
3222#endif
3223
3224#if defined(FIRST)
3225enum class E10 : int {};
3226#elif defined(SECOND)
3227enum class E10 {};
3228#else
3229E10 e10;
3230// expected-error@second.h:* {{'Enums::E10' has different definitions in different modules; definition in module 'SecondModule' first difference is enum without specified type}}
3231// expected-note@first.h:* {{but in 'FirstModule' found enum with specified type}}
3232#endif
3233
3234#if defined(FIRST)
3235enum E11 {};
3236#elif defined(SECOND)
3237enum E11 : int {};
3238#else
3239E11 e11;
3240// expected-error@second.h:* {{'Enums::E11' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type}}
3241// expected-note@first.h:* {{but in 'FirstModule' found enum without specified type}}
3242#endif
3243
3244#if defined(FIRST)
3245enum struct E12 : long {};
3246#elif defined(SECOND)
3247enum struct E12 : int {};
3248#else
3249E12 e12;
3250// expected-error@second.h:* {{'Enums::E12' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type 'int'}}
3251// expected-note@first.h:* {{but in 'FirstModule' found enum with specified type 'long'}}
3252#endif
3253
3254#if defined(FIRST)
3255enum struct E13 {};
3256#elif defined(SECOND)
3257enum E13 {};
3258#else
3259E13 e13;
3260// expected-error@second.h:* {{'Enums::E13' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is not scoped}}
3261// expected-note@first.h:* {{but in 'FirstModule' found enum that is scoped}}
3262#endif
3263
3264#if defined(FIRST)
3265enum E14 {};
3266#elif defined(SECOND)
3267enum struct E14 {};
3268#else
3269E14 e14;
3270// expected-error@second.h:* {{'Enums::E14' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is scoped}}
3271// expected-note@first.h:* {{but in 'FirstModule' found enum that is not scoped}}
3272#endif
3273
3274#if defined(FIRST)
3275enum class E15 {};
3276#elif defined(SECOND)
3277enum struct E15 {};
3278#else
3279E15 e15;
3280// expected-error@second.h:* {{'Enums::E15' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword struct}}
3281// expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword class}}
3282#endif
3283
3284#if defined(FIRST)
3285enum struct E16 {};
3286#elif defined(SECOND)
3287enum class E16 {};
3288#else
3289E16 e16;
3290// expected-error@second.h:* {{'Enums::E16' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword class}}
3291// expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword struct}}
3292#endif
3293
3294#if defined(FIRST)
3295enum Valid { v1 = (struct S*)0 == (struct S*)0 };
3296#elif defined(SECOND)
3297struct S {};
3298enum Valid { v1 = (struct S*)0 == (struct S*)0 };
3299#else
3300Valid V;
3301#endif
3302} // namespace Enums
3303
Richard Trieu22ddc282018-09-04 22:53:19 +00003304namespace Types {
3305namespace Complex {
3306#if defined(FIRST)
3307void invalid() {
3308 _Complex float x;
3309}
3310void valid() {
3311 _Complex float x;
3312}
3313#elif defined(SECOND)
3314void invalid() {
3315 _Complex double x;
3316}
3317void valid() {
3318 _Complex float x;
3319}
3320#else
3321auto function1 = invalid;
3322// expected-error@second.h:* {{'Types::Complex::invalid' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3323// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3324auto function2 = valid;
3325#endif
3326} // namespace Complex
3327
3328namespace Decltype {
3329#if defined(FIRST)
3330void invalid1() {
3331 decltype(1 + 1) x;
3332}
3333int global;
3334void invalid2() {
3335 decltype(global) x;
3336}
3337void valid() {
3338 decltype(1.5) x;
3339 decltype(x) y;
3340}
3341#elif defined(SECOND)
3342void invalid1() {
3343 decltype(2) x;
3344}
3345float global;
3346void invalid2() {
3347 decltype(global) x;
3348}
3349void valid() {
3350 decltype(1.5) x;
3351 decltype(x) y;
3352}
3353#else
3354auto function1 = invalid1;
3355// expected-error@second.h:* {{'Types::Decltype::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3356// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3357auto function2 = invalid2;
3358// expected-error@second.h:* {{'Types::Decltype::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3359// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3360auto function3 = valid;
3361#endif
3362} // namespace Decltype
3363
3364namespace Auto {
3365#if defined(FIRST)
3366void invalid1() {
3367 decltype(auto) x = 1;
3368}
3369void invalid2() {
3370 auto x = 1;
3371}
3372void invalid3() {
3373 __auto_type x = 1;
3374}
3375void valid() {
3376 decltype(auto) x = 1;
3377 auto y = 1;
3378 __auto_type z = 1;
3379}
3380#elif defined(SECOND)
3381void invalid1() {
3382 auto x = 1;
3383}
3384void invalid2() {
3385 __auto_type x = 1;
3386}
3387void invalid3() {
3388 decltype(auto) x = 1;
3389}
3390void valid() {
3391 decltype(auto) x = 1;
3392 auto y = 1;
3393 __auto_type z = 1;
3394}
3395#else
3396auto function1 = invalid1;
3397// expected-error@second.h:* {{'Types::Auto::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3398// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3399auto function2 = invalid3;
3400// expected-error@second.h:* {{'Types::Auto::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3401// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3402auto function3 = invalid2;
3403// expected-error@second.h:* {{'Types::Auto::invalid3' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3404// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3405auto function4 = valid;
3406#endif
3407} // namespace Auto
3408
3409namespace DeducedTemplateSpecialization {
3410#if defined(FIRST)
3411template<typename T> struct A {};
3412A() -> A<int>;
3413template<typename T> struct B {};
3414B() -> B<int>;
3415
3416void invalid1() {
3417 A a{};
3418}
3419void invalid2() {
3420 A a{};
3421}
3422void valid() {
3423 B b{};
3424}
3425#elif defined(SECOND)
3426template<typename T> struct A {};
3427A() -> A<float>;
3428template<typename T> struct B {};
3429B() -> B<int>;
3430
3431void invalid1() {
3432 A a{};
3433}
3434void invalid2() {
3435 B a{};
3436}
3437void valid() {
3438 B b{};
3439}
3440#else
3441auto function1 = invalid1;
3442// expected-error@second.h:* {{'Types::DeducedTemplateSpecialization::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3443// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3444auto function2 = invalid2;
3445// expected-error@second.h:* {{'Types::DeducedTemplateSpecialization::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3446// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3447auto function3 = valid;
3448#endif
3449} // namespace DeducedTemplateSpecialization
3450
3451namespace DependentAddressSpace {
3452#if defined(FIRST)
3453template <int A1, int A2>
3454void invalid1() {
3455 using type = int __attribute__((address_space(A1)));
3456}
3457template <int A1>
3458void invalid2() {
3459 using type = float __attribute__((address_space(A1)));
3460}
3461template <int A1, int A2>
3462void valid() {
3463 using type1 = float __attribute__((address_space(A1)));
3464 using type2 = int __attribute__((address_space(A2)));
3465 using type3 = int __attribute__((address_space(A1 + A2)));
3466}
3467#elif defined(SECOND)
3468template <int A1, int A2>
3469void invalid1() {
3470 using type = int __attribute__((address_space(A2)));
3471}
3472template <int A1>
3473void invalid2() {
3474 using type = int __attribute__((address_space(A1)));
3475}
3476template <int A1, int A2>
3477void valid() {
3478 using type1 = float __attribute__((address_space(A1)));
3479 using type2 = int __attribute__((address_space(A2)));
3480 using type3 = int __attribute__((address_space(A1 + A2)));
3481}
3482#else
3483template <int A, int B>
3484class S {
3485 static auto function1 = invalid1<A, B>;
3486 // expected-error@first.h:* {{'Types::DependentAddressSpace::invalid1' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3487 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3488 static auto function2 = invalid2<B>;
3489 // expected-error@first.h:* {{'Types::DependentAddressSpace::invalid2' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3490 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3491 static auto function3 = valid<A, B>;
3492};
3493#endif
3494} // namespace DependentAddressSpace
3495
3496namespace DependentSizedExtVector {
3497#if defined(FIRST)
3498template<int Size>
3499void invalid1() {
3500 typedef int __attribute__((ext_vector_type(Size))) type;
3501}
3502template<int Size>
3503void invalid2() {
3504 typedef int __attribute__((ext_vector_type(Size + 0))) type;
3505}
3506template<int Size>
3507void valid() {
3508 typedef int __attribute__((ext_vector_type(Size))) type;
3509}
3510#elif defined(SECOND)
3511template<int Size>
3512void invalid1() {
3513 typedef float __attribute__((ext_vector_type(Size))) type;
3514}
3515template<int Size>
3516void invalid2() {
3517 typedef int __attribute__((ext_vector_type(Size + 1))) type;
3518}
3519template<int Size>
3520void valid() {
3521 typedef int __attribute__((ext_vector_type(Size))) type;
3522}
3523#else
3524template <int Num>
3525class S {
3526 static auto Function1 = invalid1<Num>;
3527 // expected-error@first.h:* {{'Types::DependentSizedExtVector::invalid1' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3528 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3529 static auto Function2 = invalid2<Num>;
3530 // expected-error@first.h:* {{'Types::DependentSizedExtVector::invalid2' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3531 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3532 static auto Function3 = valid<Num>;
3533};
3534#endif
3535} // namespace DependentSizedExtVector
3536
3537namespace InjectedClassName {
3538#if defined(FIRST)
3539struct Invalid {
3540 template <int>
3541 struct L2 {
3542 template <int>
3543 struct L3 {
3544 L3 *x;
3545 };
3546 };
3547};
3548struct Valid {
3549 template <int>
3550 struct L2 {
3551 template <int>
3552 struct L3 {
3553 L2 *x;
3554 L3 *y;
3555 };
3556 };
3557};
3558#elif defined(SECOND)
3559struct Invalid {
3560 template <int>
3561 struct L2 {
3562 template <int>
3563 struct L3 {
3564 L2 *x;
3565 };
3566 };
3567};
3568struct Valid {
3569 template <int>
3570 struct L2 {
3571 template <int>
3572 struct L3 {
3573 L2 *x;
3574 L3 *y;
3575 };
3576 };
3577};
3578#else
3579Invalid::L2<1>::L3<1> invalid;
3580// expected-error@second.h:* {{'Types::InjectedClassName::Invalid::L2::L3::x' from module 'SecondModule' is not present in definition of 'L3<>' in module 'FirstModule'}}
3581// expected-note@first.h:* {{declaration of 'x' does not match}}
3582Valid::L2<1>::L3<1> valid;
3583#endif
3584} // namespace InjectedClassName
3585
3586namespace MemberPointer {
3587#if defined(FIRST)
3588struct A {};
3589struct B {};
3590
3591void Invalid1() {
3592 int A::*x;
3593};
3594void Invalid2() {
3595 int A::*x;
3596}
3597void Invalid3() {
3598 int (A::*x)(int);
3599}
3600void Valid() {
3601 int A::*x;
3602 float A::*y;
3603 bool B::*z;
3604 void (A::*fun1)();
3605 int (A::*fun2)();
3606 void (B::*fun3)(int);
3607 void (B::*fun4)(bool*, int);
3608}
3609#elif defined(SECOND)
3610struct A {};
3611struct B {};
3612
3613void Invalid1() {
3614 float A::*x;
3615};
3616void Invalid2() {
3617 int B::*x;
3618}
3619void Invalid3() {
3620 int (A::*x)(int, int);
3621}
3622void Valid() {
3623 int A::*x;
3624 float A::*y;
3625 bool B::*z;
3626 void (A::*fun1)();
3627 int (A::*fun2)();
3628 void (B::*fun3)(int);
3629 void (B::*fun4)(bool*, int);
3630}
3631#else
3632auto function1 = Invalid1;
3633// expected-error@second.h:* {{'Types::MemberPointer::Invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3634// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3635auto function2 = Invalid2;
3636// expected-error@second.h:* {{'Types::MemberPointer::Invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3637// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3638auto function3 = Invalid3;
3639// expected-error@second.h:* {{'Types::MemberPointer::Invalid3' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3640// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3641auto function4 = Valid;
3642#endif
3643
3644} // namespace MemberPointer
3645
3646namespace PackExpansion {
3647#if defined(FIRST)
3648struct Invalid {
3649 template <class... A>
3650 struct L2 {
3651 template <class... B>
3652 struct L3 {
3653 void run(A...);
3654 void run(B...);
3655 };
3656 };
3657};
3658struct Valid {
3659 template <class... A>
3660 struct L2 {
3661 template <class... B>
3662 struct L3 {
3663 void run(A...);
3664 void run(B...);
3665 };
3666 };
3667};
3668#elif defined(SECOND)
3669struct Invalid {
3670 template <class... A>
3671 struct L2 {
3672 template <class... B>
3673 struct L3 {
3674 void run(B...);
3675 void run(A...);
3676 };
3677 };
3678};
3679struct Valid {
3680 template <class... A>
3681 struct L2 {
3682 template <class... B>
3683 struct L3 {
3684 void run(A...);
3685 void run(B...);
3686 };
3687 };
3688};
3689#else
3690Invalid::L2<int>::L3<short, bool> invalid;
3691// expected-error@first.h:* {{'Types::PackExpansion::Invalid::L2::L3' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'run' with 1st parameter of type 'A...'}}
3692// expected-note@second.h:* {{but in 'SecondModule' found method 'run' with 1st parameter of type 'B...'}}
3693Valid::L2<int>::L3<short, bool> valid;
3694#endif
3695
3696} // namespace PackExpansion
3697
3698namespace Paren {
3699#if defined(FIRST)
3700void invalid() {
3701 int (*x);
3702}
3703void valid() {
3704 int (*x);
3705}
3706#elif defined(SECOND)
3707void invalid() {
3708 float (*x);
3709}
3710void valid() {
3711 int (*x);
3712}
3713#else
3714auto function1 = invalid;
3715// expected-error@second.h:* {{'Types::Paren::invalid' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3716// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3717auto function2 = valid;
3718#endif
3719} // namespace Paren
3720
3721namespace SubstTemplateTypeParm {
3722#if defined(FIRST)
3723template <class> struct wrapper {};
3724template <class, class, class> struct triple {};
3725struct Valid {
3726 template <class T,
3727 template <class _T, class _U, class = wrapper<_T>> class A = triple>
3728 struct L2 {
3729 A<T, T> x;
3730 };
3731};
3732#elif defined(SECOND)
3733template <class> struct wrapper {};
3734template <class, class, class> struct triple {};
3735struct Valid {
3736 template <class T,
3737 template <class _T, class _U, class = wrapper<_T>> class A = triple>
3738 struct L2 {
3739 A<T, T> x;
3740 };
3741};
3742#else
3743template <class T,
3744 template <class _T, class _U, class = wrapper<_T>> class A = triple>
3745using V = Valid::L2<T, A>;
3746#endif
3747} // namespace SubstTemplateTypeParm
3748
3749namespace SubstTemplateTypeParmPack {
3750} // namespace SubstTemplateTypeParmPack
3751
3752namespace UnaryTransform {
3753#if defined(FIRST)
3754enum class E1a : unsigned {};
3755struct Invalid1 {
3756 __underlying_type(E1a) x;
3757};
3758enum E2a : unsigned {};
3759struct Invalid2 {
3760 __underlying_type(E2a) x;
3761};
3762enum E3a {};
3763struct Invalid3 {
3764 __underlying_type(E3a) x;
3765};
3766enum E4a {};
3767struct Invalid4 {
3768 __underlying_type(E4a) x;
3769};
3770enum E1 {};
3771struct Valid1 {
3772 __underlying_type(E1) x;
3773};
3774enum E2 : unsigned {};
3775struct Valid2 {
3776 __underlying_type(E2) x;
3777};
3778enum class E3 {};
3779struct Valid3 {
3780 __underlying_type(E3) x;
3781};
3782#elif defined(SECOND)
3783enum class E1b : signed {};
3784struct Invalid1 {
3785 __underlying_type(E1b) x;
3786};
3787enum class E2b : unsigned {};
3788struct Invalid2 {
3789 __underlying_type(E2b) x;
3790};
3791enum E3b : int {};
3792struct Invalid3 {
3793 __underlying_type(E3b) x;
3794};
3795enum E4b {};
3796struct Invalid4 {
3797 __underlying_type(E4b) x;
3798};
3799#else
3800Invalid1 i1;
3801// expected-error@first.h:* {{'Types::UnaryTransform::Invalid1::x' from module 'FirstModule' is not present in definition of 'Types::UnaryTransform::Invalid1' in module 'SecondModule'}}
3802// expected-note@second.h:* {{declaration of 'x' does not match}}
3803Invalid2 i2;
3804// expected-error@second.h:* {{'Types::UnaryTransform::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '__underlying_type(Types::UnaryTransform::E2b)' (aka 'unsigned int')}}
3805// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type '__underlying_type(Types::UnaryTransform::E2a)' (aka 'unsigned int')}}
3806Invalid3 i3;
3807// expected-error@first.h:* {{'Types::UnaryTransform::Invalid3::x' from module 'FirstModule' is not present in definition of 'Types::UnaryTransform::Invalid3' in module 'SecondModule'}}
3808// expected-note@second.h:* {{declaration of 'x' does not match}}
3809Invalid4 i4;
3810// expected-error@second.h:* {{'Types::UnaryTransform::Invalid4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '__underlying_type(Types::UnaryTransform::E4b)' (aka 'unsigned int')}}
3811// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type '__underlying_type(Types::UnaryTransform::E4a)' (aka 'unsigned int')}}
3812Valid1 v1;
3813Valid2 v2;
3814Valid3 v3;
3815#endif
3816} // namespace UnaryTransform
3817
3818namespace UnresolvedUsing {
3819#if defined(FIRST)
3820template <class T> struct wrapper {};
3821template <class T>
3822struct Invalid {
3823 using typename wrapper<T>::T1;
3824 using typename wrapper<T>::T2;
3825 T1 x;
3826};
3827template <class T>
3828struct Valid {
3829 using typename wrapper<T>::T1;
3830 using typename wrapper<T>::T2;
3831 T1 x;
3832 T2 y;
3833};
3834#elif defined(SECOND)
3835template <class T> struct wrapper {};
3836template <class T>
3837struct Invalid {
3838 using typename wrapper<T>::T1;
3839 using typename wrapper<T>::T2;
3840 T2 x;
3841};
3842template <class T>
3843struct Valid {
3844 using typename wrapper<T>::T1;
3845 using typename wrapper<T>::T2;
3846 T1 x;
3847 T2 y;
3848};
3849#else
3850template <class T> using I = Invalid<T>;
3851// expected-error@first.h:* {{'Types::UnresolvedUsing::Invalid::x' from module 'FirstModule' is not present in definition of 'Invalid<T>' in module 'SecondModule'}}
3852// expected-note@second.h:* {{declaration of 'x' does not match}}
3853
3854template <class T> using V = Valid<T>;
3855#endif
3856
3857} // namespace UnresolvedUsing
3858
3859// Vector
3860// void invalid1() {
3861// __attribute((vector_size(8))) int *x1;
3862//}
3863
3864} // namespace Types
3865
Richard Trieu73cf9242017-11-04 01:20:50 +00003866// Collection of interesting cases below.
3867
3868// Naive parsing of AST can lead to cycles in processing. Ensure
3869// self-references don't trigger an endless cycles of AST node processing.
3870namespace SelfReference {
3871#if defined(FIRST)
3872template <template <int> class T> class Wrapper {};
3873
3874template <int N> class S {
3875 S(Wrapper<::SelfReference::S> &Ref) {}
3876};
3877
3878struct Xx {
3879 struct Yy {
Richard Trieufe564052017-04-20 02:53:53 +00003880 };
Richard Trieu73cf9242017-11-04 01:20:50 +00003881};
Richard Trieufe564052017-04-20 02:53:53 +00003882
Richard Trieu73cf9242017-11-04 01:20:50 +00003883Xx::Xx::Xx::Yy yy;
Richard Trieue7f7ed22017-02-22 01:11:25 +00003884
Richard Trieu73cf9242017-11-04 01:20:50 +00003885namespace NNS {
3886template <typename> struct Foo;
3887template <template <class> class T = NNS::Foo>
3888struct NestedNamespaceSpecifier {};
Richard Trieue7f7ed22017-02-22 01:11:25 +00003889}
Richard Trieu73cf9242017-11-04 01:20:50 +00003890#endif
3891} // namespace SelfReference
Richard Trieue7f7ed22017-02-22 01:11:25 +00003892
3893namespace FriendFunction {
3894#if defined(FIRST)
3895void F(int = 0);
3896struct S { friend void F(int); };
3897#elif defined(SECOND)
3898void F(int);
3899struct S { friend void F(int); };
3900#else
3901S s;
3902#endif
3903
3904#if defined(FIRST)
3905void G(int = 0);
3906struct T {
3907 friend void G(int);
3908
3909 private:
3910};
3911#elif defined(SECOND)
3912void G(int);
3913struct T {
3914 friend void G(int);
3915
3916 public:
3917};
3918#else
3919T t;
3920// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3921// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3922#endif
3923} // namespace FriendFunction
3924
3925namespace ImplicitDecl {
3926#if defined(FIRST)
3927struct S { };
3928void S_Constructors() {
3929 // Trigger creation of implicit contructors
3930 S foo;
3931 S bar = foo;
3932 S baz(bar);
3933}
3934#elif defined(SECOND)
3935struct S { };
3936#else
3937S s;
3938#endif
3939
3940#if defined(FIRST)
3941struct T {
3942 private:
3943};
3944void T_Constructors() {
3945 // Trigger creation of implicit contructors
3946 T foo;
3947 T bar = foo;
3948 T baz(bar);
3949}
3950#elif defined(SECOND)
3951struct T {
3952 public:
3953};
3954#else
3955T t;
3956// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
3957// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
3958#endif
3959
Richard Trieu73cf9242017-11-04 01:20:50 +00003960} // namespace ImplicitDecl
Richard Trieue7f7ed22017-02-22 01:11:25 +00003961
3962namespace TemplatedClass {
3963#if defined(FIRST)
3964template <class>
3965struct S {};
3966#elif defined(SECOND)
3967template <class>
3968struct S {};
3969#else
3970S<int> s;
3971#endif
3972
3973#if defined(FIRST)
3974template <class>
3975struct T {
3976 private:
3977};
3978#elif defined(SECOND)
3979template <class>
3980struct T {
3981 public:
3982};
3983#else
3984T<int> t;
3985// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3986// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
3987#endif
3988} // namespace TemplatedClass
3989
3990namespace TemplateClassWithField {
3991#if defined(FIRST)
3992template <class A>
3993struct S {
3994 A a;
3995};
3996#elif defined(SECOND)
3997template <class A>
3998struct S {
3999 A a;
4000};
4001#else
4002S<int> s;
4003#endif
4004
4005#if defined(FIRST)
4006template <class A>
4007struct T {
4008 A a;
4009
4010 private:
4011};
4012#elif defined(SECOND)
4013template <class A>
4014struct T {
4015 A a;
4016
4017 public:
4018};
4019#else
4020T<int> t;
4021// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
4022// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
4023#endif
4024} // namespace TemplateClassWithField
4025
4026namespace TemplateClassWithTemplateField {
4027#if defined(FIRST)
4028template <class A>
4029class WrapperS;
4030template <class A>
4031struct S {
4032 WrapperS<A> a;
4033};
4034#elif defined(SECOND)
4035template <class A>
4036class WrapperS;
4037template <class A>
4038struct S {
4039 WrapperS<A> a;
4040};
4041#else
4042template <class A>
4043class WrapperS{};
4044S<int> s;
4045#endif
4046
4047#if defined(FIRST)
4048template <class A>
4049class WrapperT;
4050template <class A>
4051struct T {
4052 WrapperT<A> a;
4053
4054 public:
4055};
4056#elif defined(SECOND)
4057template <class A>
4058class WrapperT;
4059template <class A>
4060struct T {
4061 WrapperT<A> a;
4062
4063 private:
4064};
4065#else
4066template <class A>
4067class WrapperT{};
4068T<int> t;
4069// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4070// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4071#endif
4072} // namespace TemplateClassWithTemplateField
4073
4074namespace EnumWithForwardDeclaration {
4075#if defined(FIRST)
4076enum E : int;
4077struct S {
4078 void get(E) {}
4079};
4080#elif defined(SECOND)
4081enum E : int { A, B };
4082struct S {
4083 void get(E) {}
4084};
4085#else
4086S s;
4087#endif
4088
4089#if defined(FIRST)
4090struct T {
4091 void get(E) {}
4092 public:
4093};
4094#elif defined(SECOND)
4095struct T {
4096 void get(E) {}
4097 private:
4098};
4099#else
4100T t;
4101// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4102// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4103#endif
4104} // namespace EnumWithForwardDeclaration
4105
4106namespace StructWithForwardDeclaration {
4107#if defined(FIRST)
4108struct P {};
4109struct S {
4110 struct P *ptr;
4111};
4112#elif defined(SECOND)
4113struct S {
4114 struct P *ptr;
4115};
4116#else
4117S s;
4118#endif
4119
4120#if defined(FIRST)
4121struct Q {};
4122struct T {
4123 struct Q *ptr;
4124 public:
4125};
4126#elif defined(SECOND)
4127struct T {
4128 struct Q *ptr;
4129 private:
4130};
4131#else
4132T t;
4133// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4134// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4135#endif
4136} // namespace StructWithForwardDeclaration
4137
4138namespace StructWithForwardDeclarationNoDefinition {
4139#if defined(FIRST)
4140struct P;
4141struct S {
4142 struct P *ptr;
4143};
4144#elif defined(SECOND)
4145struct S {
4146 struct P *ptr;
4147};
4148#else
4149S s;
4150#endif
4151
4152#if defined(FIRST)
4153struct Q;
4154struct T {
4155 struct Q *ptr;
4156
4157 public:
4158};
4159#elif defined(SECOND)
4160struct T {
4161 struct Q *ptr;
4162
4163 private:
4164};
4165#else
4166T t;
4167// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4168// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4169#endif
4170} // namespace StructWithForwardDeclarationNoDefinition
4171
Richard Trieufe564052017-04-20 02:53:53 +00004172namespace LateParsedDefaultArgument {
4173#if defined(FIRST)
4174template <typename T>
4175struct S {
4176 struct R {
4177 void foo(T x = 0) {}
4178 };
4179};
4180#elif defined(SECOND)
4181#else
4182void run() {
4183 S<int>::R().foo();
4184}
4185#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004186} // namespace LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00004187
4188namespace LateParsedDefaultArgument {
4189#if defined(FIRST)
4190template <typename alpha> struct Bravo {
4191 void charlie(bool delta = false) {}
4192};
4193typedef Bravo<char> echo;
4194echo foxtrot;
4195
4196Bravo<char> golf;
4197#elif defined(SECOND)
4198#else
4199#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004200} // LateParsedDefaultArgument
Richard Trieufe564052017-04-20 02:53:53 +00004201
Richard Trieu157ed942017-04-28 22:03:28 +00004202namespace DifferentParameterNameInTemplate {
4203#if defined(FIRST) || defined(SECOND)
4204template <typename T>
4205struct S {
4206 typedef T Type;
4207
4208 static void Run(const Type *name_one);
4209};
4210
4211template <typename T>
4212void S<T>::Run(const T *name_two) {}
4213
4214template <typename T>
4215struct Foo {
4216 ~Foo() { Handler::Run(nullptr); }
4217 Foo() {}
4218
4219 class Handler : public S<T> {};
4220
4221 void Get(typename Handler::Type *x = nullptr) {}
4222 void Add() { Handler::Run(nullptr); }
4223};
4224#endif
4225
4226#if defined(FIRST)
4227struct Beta;
4228
4229struct Alpha {
4230 Alpha();
4231 void Go() { betas.Get(); }
4232 Foo<Beta> betas;
4233};
4234
4235#elif defined(SECOND)
4236struct Beta {};
4237
4238struct BetaHelper {
4239 void add_Beta() { betas.Add(); }
4240 Foo<Beta> betas;
4241};
4242
4243#else
4244Alpha::Alpha() {}
4245#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004246} // DifferentParameterNameInTemplate
Richard Trieu157ed942017-04-28 22:03:28 +00004247
Richard Trieu02552272017-05-02 23:58:52 +00004248namespace ParameterTest {
4249#if defined(FIRST)
4250class X {};
4251template <typename G>
4252class S {
4253 public:
4254 typedef G Type;
4255 static inline G *Foo(const G *a, int * = nullptr);
4256};
4257
4258template<typename G>
4259G* S<G>::Foo(const G* aaaa, int*) {}
4260#elif defined(SECOND)
4261template <typename G>
4262class S {
4263 public:
4264 typedef G Type;
4265 static inline G *Foo(const G *a, int * = nullptr);
4266};
4267
4268template<typename G>
4269G* S<G>::Foo(const G* asdf, int*) {}
4270#else
4271S<X> s;
4272#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004273} // ParameterTest
Richard Trieu02552272017-05-02 23:58:52 +00004274
Richard Trieub35ef2a2017-05-09 03:24:34 +00004275namespace MultipleTypedefs {
4276#if defined(FIRST)
4277typedef int B1;
4278typedef B1 A1;
4279struct S1 {
4280 A1 x;
4281};
4282#elif defined(SECOND)
4283typedef int A1;
4284struct S1 {
4285 A1 x;
4286};
4287#else
4288S1 s1;
4289#endif
4290
4291#if defined(FIRST)
4292struct T2 { int x; };
4293typedef T2 B2;
4294typedef B2 A2;
4295struct S2 {
4296 T2 x;
4297};
4298#elif defined(SECOND)
4299struct T2 { int x; };
4300typedef T2 A2;
4301struct S2 {
4302 T2 x;
4303};
4304#else
4305S2 s2;
4306#endif
Richard Trieu3e03d3e2017-06-29 22:53:04 +00004307
4308#if defined(FIRST)
4309using A3 = const int;
4310using B3 = volatile A3;
4311struct S3 {
4312 B3 x = 1;
4313};
4314#elif defined(SECOND)
4315using A3 = volatile const int;
4316using B3 = A3;
4317struct S3 {
4318 B3 x = 1;
4319};
4320#else
4321S3 s3;
4322#endif
Richard Trieucaaccee2018-04-12 02:26:49 +00004323
4324#if defined(FIRST)
4325using A4 = int;
4326using B4 = A4;
4327struct S4 {
4328 B4 x;
4329};
4330#elif defined(SECOND)
4331using A4 = int;
4332using B4 = ::MultipleTypedefs::A4;
4333struct S4 {
4334 B4 x;
4335};
4336#else
4337S4 s4;
4338#endif
4339
4340#if defined(FIRST)
4341using A5 = int;
4342using B5 = MultipleTypedefs::A5;
4343struct S5 {
4344 B5 x;
4345};
4346#elif defined(SECOND)
4347using A5 = int;
4348using B5 = ::MultipleTypedefs::A5;
4349struct S5 {
4350 B5 x;
4351};
4352#else
4353S5 s5;
4354#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004355} // MultipleTypedefs
4356
4357namespace DefaultArguments {
4358#if defined(FIRST)
4359template <typename T>
4360struct S {
4361 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00004362 void foo(T x = 0);
Richard Trieu73cf9242017-11-04 01:20:50 +00004363 };
4364};
4365#elif defined(SECOND)
4366template <typename T>
4367struct S {
4368 struct R {
Richard Trieue6caa262017-12-23 00:41:01 +00004369 void foo(T x = 1);
Richard Trieu73cf9242017-11-04 01:20:50 +00004370 };
4371};
4372#else
4373void run() {
4374 S<int>::R().foo();
Richard Trieub35ef2a2017-05-09 03:24:34 +00004375}
Richard Trieu73cf9242017-11-04 01:20:50 +00004376// 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}}
4377// expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}}
4378#endif
4379
4380#if defined(FIRST)
4381template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00004382 void charlie(bool delta = false);
Richard Trieu73cf9242017-11-04 01:20:50 +00004383};
4384typedef Bravo<char> echo;
4385echo foxtrot;
4386#elif defined(SECOND)
4387template <typename alpha> struct Bravo {
Richard Trieue6caa262017-12-23 00:41:01 +00004388 void charlie(bool delta = (false));
Richard Trieu73cf9242017-11-04 01:20:50 +00004389};
4390typedef Bravo<char> echo;
4391echo foxtrot;
4392#else
4393Bravo<char> golf;
4394// 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}}
4395// expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}}
4396#endif
4397} // namespace DefaultArguments
Richard Trieu02552272017-05-02 23:58:52 +00004398
Richard Trieue6caa262017-12-23 00:41:01 +00004399namespace FunctionDecl {
4400#if defined(FIRST)
4401struct S1 {};
4402S1 s1a;
4403#elif defined(SECOND)
4404struct S1 {};
4405#else
4406S1 s1;
4407#endif
4408
4409#if defined(FIRST)
4410struct S2 {
4411 S2() = default;
4412};
4413S2 s2a = S2();
4414#elif defined(SECOND)
4415struct S2 {
4416 S2() = default;
4417};
4418#else
4419S2 s2;
4420#endif
4421
4422#if defined(FIRST)
4423struct S3 {
4424 S3() = delete;
4425};
4426S3* s3c;
4427#elif defined(SECOND)
4428struct S3 {
4429 S3() = delete;
4430};
4431#else
4432S3* s3;
4433#endif
4434
4435#if defined(FIRST) || defined(SECOND)
4436int F1(int x, float y = 2.7) { return 1; }
4437#else
4438int I1 = F1(1);
4439#endif
4440
4441#if defined(FIRST)
4442int F2() { return 1; }
4443#elif defined(SECOND)
4444double F2() { return 1; }
4445#else
4446int I2 = F2();
4447// expected-error@-1 {{call to 'F2' is ambiguous}}
4448// expected-note@first.h:* {{candidate function}}
4449// expected-note@second.h:* {{candidate function}}
4450#endif
4451
4452#if defined(FIRST)
4453int F3(float) { return 1; }
4454#elif defined(SECOND)
4455int F3(double) { return 1; }
4456#else
4457int I3 = F3(1);
4458// expected-error@-1 {{call to 'F3' is ambiguous}}
4459// expected-note@first.h:* {{candidate function}}
4460// expected-note@second.h:* {{candidate function}}
4461#endif
4462
4463#if defined(FIRST)
4464int F4(int x) { return 1; }
4465#elif defined(SECOND)
4466int F4(int y) { return 1; }
4467#else
4468int I4 = F4(1);
4469// expected-error@second.h:* {{'FunctionDecl::F4' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with name 'y'}}
4470// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with name 'x'}}
4471#endif
4472
4473#if defined(FIRST)
4474int F5(int x) { return 1; }
4475#elif defined(SECOND)
4476int F5(int x = 1) { return 1; }
4477#else
4478int I5 = F6(1);
4479// 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}}
4480// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a default argument}}
4481#endif
4482
4483#if defined(FIRST)
4484int F6(int x = 2) { return 1; }
4485#elif defined(SECOND)
4486int F6(int x = 1) { return 1; }
4487#else
4488int I6 = F6(1);
4489// 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}}
4490// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a different default argument}}
4491#endif
4492
4493using I = int;
4494#if defined(FIRST)
4495I F7() { return 0; }
4496#elif defined(SECOND)
4497int F7() { return 0; }
4498#else
4499int I7 = F7();
4500// expected-error@second.h:* {{'FunctionDecl::F7' has different definitions in different modules; definition in module 'SecondModule' first difference is return type is 'int'}}
4501// expected-note@first.h:* {{but in 'FirstModule' found different return type 'FunctionDecl::I' (aka 'int')}}
4502#endif
4503
4504#if defined(FIRST)
4505int F8(int) { return 0; }
4506#elif defined(SECOND)
4507int F8(I) { return 0; }
4508#else
4509int I8 = F8(1);
4510// 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')}}
4511// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int'}}
4512#endif
4513
4514#if defined(FIRST)
4515int F9(int[1]) { return 0; }
4516#elif defined(SECOND)
4517int F9(int[2]) { return 0; }
4518#else
4519int I9 = F9(nullptr);
4520// 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]'}}
4521// expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int *' decayed from 'int [1]'}}
4522#endif
4523
4524#if defined(FIRST)
4525int F10() { return 1; }
4526#elif defined(SECOND)
4527int F10() { return 2; }
4528#else
4529int I10 = F10();
4530#endif
4531// expected-error@second.h:* {{'FunctionDecl::F10' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
4532// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
Richard Trieu5d014062018-06-07 00:20:58 +00004533
4534#if defined(FIRST)
4535struct S11 {
4536 template <int> void foo();
4537};
4538#elif defined(SECOND)
4539struct S11 {
4540 template <int> void foo();
4541};
4542template <int> void S11::foo() {}
4543#else
4544S11 s11;
4545#endif
4546
Richard Trieu27c1b1a2018-07-10 01:40:50 +00004547#if defined(FIRST)
4548struct S12 {
4549 void foo(int x);
4550};
4551#elif defined(SECOND)
4552struct S12 {
4553 void foo(int x);
4554};
4555void S12::foo(int y) {}
4556#else
4557S12 s12;
4558#endif
4559
4560#if defined(FIRST)
4561struct S13 {
4562 void foo(int x);
4563};
4564void S13::foo(int y) {}
4565#elif defined(SECOND)
4566struct S13 {
4567 void foo(int x);
4568};
4569void S13::foo(int y) {}
4570#else
4571S13 s13;
4572#endif
Richard Trieue6caa262017-12-23 00:41:01 +00004573} // namespace FunctionDecl
4574
Richard Trieu4d06bef2018-02-13 19:53:40 +00004575namespace DeclTemplateArguments {
4576#if defined(FIRST)
4577int foo() { return 1; }
4578int bar() { return foo(); }
4579#elif defined(SECOND)
4580template <class T = int>
4581int foo() { return 2; }
4582int bar() { return foo<>(); }
4583#else
4584int num = bar();
4585// expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
4586// expected-note@first.h:* {{but in 'FirstModule' found a different body}}
4587#endif
4588}
4589
Richard Trieue7f7ed22017-02-22 01:11:25 +00004590// Keep macros contained to one file.
4591#ifdef FIRST
4592#undef FIRST
4593#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004594
Richard Trieue7f7ed22017-02-22 01:11:25 +00004595#ifdef SECOND
4596#undef SECOND
4597#endif
Richard Trieu73cf9242017-11-04 01:20:50 +00004598
4599#ifdef ACCESS
4600#undef ACCESS
4601#endif