Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / odr_hash.cpp
blob7954a1f5f2e50be4656a32daf8a5b3920af26a76
1 // Clear and create directories
2 // RUN: rm -rf %t
3 // RUN: mkdir %t
4 // RUN: mkdir %t/cache
5 // RUN: mkdir %t/Inputs
7 // Build first header file
8 // RUN: echo "#define FIRST" >> %t/Inputs/first.h
9 // RUN: cat %s >> %t/Inputs/first.h
11 // Build second header file
12 // RUN: echo "#define SECOND" >> %t/Inputs/second.h
13 // RUN: cat %s >> %t/Inputs/second.h
15 // 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
19 // 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
27 // Run test
28 // 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
32 #if !defined(FIRST) && !defined(SECOND)
33 #include "first.h"
34 #include "second.h"
35 #endif
37 // Used for testing
38 #if defined(FIRST)
39 #define ACCESS public:
40 #elif defined(SECOND)
41 #define ACCESS private:
42 #endif
44 namespace AccessSpecifiers {
45 #if defined(FIRST)
46 struct S1 {
48 #elif defined(SECOND)
49 struct S1 {
50 private:
52 #else
53 S1 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
58 #if defined(FIRST)
59 struct S2 {
60 public:
62 #elif defined(SECOND)
63 struct S2 {
64 protected:
66 #else
67 S2 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
72 #define DECLS \
73 public: \
74 private: \
75 protected:
77 #if defined(FIRST) || defined(SECOND)
78 struct Valid1 {
79 DECLS
81 #else
82 Valid1 v1;
83 #endif
85 #if defined(FIRST) || defined(SECOND)
86 struct Invalid1 {
87 DECLS
88 ACCESS
90 #else
91 Invalid1 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
96 #undef DECLS
97 } // namespace AccessSpecifiers
99 namespace StaticAssert {
100 #if defined(FIRST)
101 struct S1 {
102 static_assert(1 == 1, "First");
104 #elif defined(SECOND)
105 struct S1 {
106 static_assert(1 == 1, "Second");
108 #else
109 S1 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
114 #if defined(FIRST)
115 struct S2 {
116 static_assert(2 == 2, "Message");
118 #elif defined(SECOND)
119 struct S2 {
120 static_assert(2 == 2);
122 #else
123 S2 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
128 #if defined(FIRST)
129 struct S3 {
130 static_assert(3 == 3, "Message");
132 #elif defined(SECOND)
133 struct S3 {
134 static_assert(3 != 4, "Message");
136 #else
137 S3 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
142 #if defined(FIRST)
143 struct S4 {
144 static_assert(4 == 4, "Message");
146 #elif defined(SECOND)
147 struct S4 {
148 public:
150 #else
151 S4 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
156 #define DECLS \
157 static_assert(4 == 4, "Message"); \
158 static_assert(5 == 5);
160 #if defined(FIRST) || defined(SECOND)
161 struct Valid1 {
162 DECLS
164 #else
165 Valid1 v1;
166 #endif
168 #if defined(FIRST) || defined(SECOND)
169 struct Invalid1 {
170 DECLS
171 ACCESS
173 #else
174 Invalid1 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
181 namespace Field {
182 #if defined(FIRST)
183 struct S1 {
184 int x;
185 private:
186 int y;
188 #elif defined(SECOND)
189 struct S1 {
190 int x;
191 int y;
193 #else
194 S1 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
199 #if defined(FIRST)
200 struct S2 {
201 int x;
202 int y;
204 #elif defined(SECOND)
205 struct S2 {
206 int y;
207 int x;
209 #else
210 S2 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
215 #if defined(FIRST)
216 struct S3 {
217 double x;
219 #elif defined(SECOND)
220 struct S3 {
221 int x;
223 #else
224 S3 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
229 #if defined(FIRST)
230 typedef int A;
231 struct S4 {
232 A x;
235 struct S5 {
236 A x;
238 #elif defined(SECOND)
239 typedef int B;
240 struct S4 {
241 B x;
244 struct S5 {
245 int x;
247 #else
248 S4 s4;
249 // expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'B' (aka 'int')}}
250 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}}
252 S5 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'}}
254 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}}
255 #endif
257 #if defined(FIRST)
258 struct S6 {
259 unsigned x;
261 #elif defined(SECOND)
262 struct S6 {
263 unsigned x : 1;
265 #else
266 S6 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
271 #if defined(FIRST)
272 struct S7 {
273 unsigned x : 2;
275 #elif defined(SECOND)
276 struct S7 {
277 unsigned x : 1;
279 #else
280 S7 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
285 #if defined(FIRST)
286 struct S8 {
287 unsigned x : 2;
289 #elif defined(SECOND)
290 struct S8 {
291 unsigned x : 1 + 1;
293 #else
294 S8 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
299 #if defined(FIRST)
300 struct S9 {
301 mutable int x;
303 #elif defined(SECOND)
304 struct S9 {
305 int x;
307 #else
308 S9 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
313 #if defined(FIRST)
314 struct S9b {
315 mutable int x : 2;
317 #elif defined(SECOND)
318 struct S9b {
319 int x : 2;
321 #else
322 S9b s9b;
323 // expected-error@second.h:* {{'Field::S9b' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
324 // expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}}
325 #endif
327 #if defined(FIRST)
328 struct S10 {
329 unsigned x = 5;
331 #elif defined(SECOND)
332 struct S10 {
333 unsigned x;
335 #else
336 S10 s10;
337 // expected-error@second.h:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initializer}}
338 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}}
339 #endif
341 #if defined(FIRST)
342 struct S11 {
343 unsigned x = 5;
345 #elif defined(SECOND)
346 struct S11 {
347 unsigned x = 7;
349 #else
350 S11 s11;
351 // 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}}
352 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
353 #endif
355 #if defined(FIRST)
356 struct S12 {
357 unsigned x[5];
359 #elif defined(SECOND)
360 struct S12 {
361 unsigned x[7];
363 #else
364 S12 s12;
365 // expected-error@first.h:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}}
366 // expected-note@second.h:* {{declaration of 'x' does not match}}
367 #endif
369 #if defined(FIRST)
370 struct S13 {
371 unsigned x[7];
373 #elif defined(SECOND)
374 struct S13 {
375 double x[7];
377 #else
378 S13 s13;
379 // expected-error@first.h:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}}
380 // expected-note@second.h:* {{declaration of 'x' does not match}}
381 #endif
383 #define DECLS \
384 int a; \
385 int b : 3; \
386 unsigned c : 1 + 2; \
387 s d; \
388 double e = 1.0; \
389 long f[5]; \
390 mutable int g; \
391 mutable int h : 5;
393 #if defined(FIRST) || defined(SECOND)
394 typedef short s;
395 #endif
397 #if defined(FIRST) || defined(SECOND)
398 struct Valid1 {
399 DECLS
401 #else
402 Valid1 v1;
403 #endif
405 #if defined(FIRST) || defined(SECOND)
406 struct Invalid1 {
407 DECLS
408 ACCESS
410 #else
411 Invalid1 i1;
412 // expected-error@second.h:* {{'Field::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
413 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
414 #endif
415 #undef DECLS
416 } // namespace Field
418 namespace Method {
419 #if defined(FIRST)
420 struct S1 {
421 void A() {}
423 #elif defined(SECOND)
424 struct S1 {
425 private:
426 void A() {}
428 #else
429 S1 s1;
430 // expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
431 // expected-note@first.h:* {{but in 'FirstModule' found method}}
432 #endif
434 #if defined(FIRST)
435 struct S2 {
436 void A() {}
437 void B() {}
439 #elif defined(SECOND)
440 struct S2 {
441 void B() {}
442 void A() {}
444 #else
445 S2 s2;
446 // expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
447 // expected-note@first.h:* {{but in 'FirstModule' found method 'A'}}
448 #endif
450 #if defined(FIRST)
451 struct S3 {
452 static void A() {}
453 void A(int) {}
455 #elif defined(SECOND)
456 struct S3 {
457 void A(int) {}
458 static void A() {}
460 #else
461 S3 s3;
462 // 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}}
463 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}}
464 #endif
466 #if defined(FIRST)
467 struct S4 {
468 virtual void A() {}
469 void B() {}
471 #elif defined(SECOND)
472 struct S4 {
473 void A() {}
474 virtual void B() {}
476 #else
477 S4 s4;
478 // 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}}
479 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}}
480 #endif
482 #if defined(FIRST)
483 struct S5 {
484 virtual void A() = 0;
485 virtual void B() {};
487 #elif defined(SECOND)
488 struct S5 {
489 virtual void A() {}
490 virtual void B() = 0;
492 #else
493 S5 *s5;
494 // expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
495 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}}
496 #endif
498 #if defined(FIRST)
499 struct S6 {
500 inline void A() {}
502 #elif defined(SECOND)
503 struct S6 {
504 void A() {}
506 #else
507 S6 s6;
508 // 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}}
509 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}}
510 #endif
512 #if defined(FIRST)
513 struct S7 {
514 void A() volatile {}
515 void A() {}
517 #elif defined(SECOND)
518 struct S7 {
519 void A() {}
520 void A() volatile {}
522 #else
523 S7 s7;
524 // 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}}
525 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}}
526 #endif
528 #if defined(FIRST)
529 struct S8 {
530 void A() const {}
531 void A() {}
533 #elif defined(SECOND)
534 struct S8 {
535 void A() {}
536 void A() const {}
538 #else
539 S8 s8;
540 // 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}}
541 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}}
542 #endif
544 #if defined(FIRST)
545 struct S9 {
546 void A(int x) {}
547 void A(int x, int y) {}
549 #elif defined(SECOND)
550 struct S9 {
551 void A(int x, int y) {}
552 void A(int x) {}
554 #else
555 S9 s9;
556 // 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}}
557 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' that has 1 parameter}}
558 #endif
560 #if defined(FIRST)
561 struct S10 {
562 void A(int x) {}
563 void A(float x) {}
565 #elif defined(SECOND)
566 struct S10 {
567 void A(float x) {}
568 void A(int x) {}
570 #else
571 S10 s10;
572 // 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'}}
573 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}}
574 #endif
576 #if defined(FIRST)
577 struct S11 {
578 void A(int x);
580 #elif defined(SECOND)
581 struct S11 {
582 void A(int y);
584 #else
585 S11 s11;
586 // 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'}}
587 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}}
588 #endif
590 #if defined(FIRST)
591 struct S12 {
592 void A(int x);
594 #elif defined(SECOND)
595 struct S12 {
596 void A(int x = 1);
598 #else
599 S12 s12;
600 // 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}}
601 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a default argument}}
602 #endif
604 #if defined(FIRST)
605 struct S13 {
606 void A(int x = 1 + 0);
608 #elif defined(SECOND)
609 struct S13 {
610 void A(int x = 1);
612 #else
613 S13 s13;
614 // 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}}
615 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter with a different default argument}}
616 #endif
618 #if defined(FIRST)
619 struct S14 {
620 void A(int x[2]);
622 #elif defined(SECOND)
623 struct S14 {
624 void A(int x[3]);
626 #else
627 S14 s14;
628 // 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]'}}
629 // expected-note@first.h:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int[2]'}}
630 #endif
632 #if defined(FIRST)
633 struct S15 {
634 int A() { return 0; }
636 #elif defined(SECOND)
637 struct S15 {
638 long A() { return 0; }
640 #else
641 S15 s15;
642 // expected-error@first.h:* {{'Method::S15::A' from module 'FirstModule' is not present in definition of 'Method::S15' in module 'SecondModule'}}
643 // expected-note@second.h:* {{declaration of 'A' does not match}}
644 #endif
646 #define DECLS \
647 void A(); \
648 static void B(); \
649 virtual void C(); \
650 virtual void D() = 0; \
651 inline void E(); \
652 void F() const; \
653 void G() volatile; \
654 void H(int x); \
655 void I(int x = 5 + 5); \
656 void J(int); \
657 void K(int x[2]); \
658 int L();
660 #if defined(FIRST) || defined(SECOND)
661 struct Valid1 {
662 DECLS
664 #else
665 Valid1* v1;
666 #endif
668 #if defined(FIRST) || defined(SECOND)
669 struct Invalid1 {
670 DECLS
671 ACCESS
673 #else
674 Invalid1* i1;
675 // expected-error@second.h:* {{'Method::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
676 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
677 #endif
678 #undef DECLS
679 } // namespace Method
681 namespace MethodBody {
682 #if defined(FIRST)
683 struct S1 {
684 int A() { return 0; }
686 #elif defined(SECOND)
687 struct S1 {
688 int A() { return 0; }
690 #else
691 S1 s1;
692 #endif
694 #if defined(FIRST)
695 struct S2 {
696 int BothBodies() { return 0; }
698 #elif defined(SECOND)
699 struct S2 {
700 int BothBodies() { return 1; }
702 #else
703 S2 s2;
704 // expected-error@first.h:* {{'MethodBody::S2' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'BothBodies' with body}}
705 // expected-note@second.h:* {{but in 'SecondModule' found method 'BothBodies' with different body}}
706 #endif
708 #if defined(FIRST)
709 struct S3 {
710 int FirstBody() { return 0; }
712 #elif defined(SECOND)
713 struct S3 {
714 int FirstBody();
716 #else
717 S3 s3;
718 // expected-error@first.h:* {{'MethodBody::S3' has different definitions in different modules; first difference is definition in module 'FirstModule' found method 'FirstBody' with body}}
719 // expected-note@second.h:* {{but in 'SecondModule' found method 'FirstBody' with no body}}
720 #endif
722 #if defined(FIRST)
723 struct S4 {
724 int SecondBody();
726 #elif defined(SECOND)
727 struct S4 {
728 int SecondBody() { return 0; }
730 #else
731 S4 s4;
732 // 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}}
733 // expected-note@second.h:* {{but in 'SecondModule' found method 'SecondBody' with body}}
734 #endif
736 #if defined(FIRST)
737 struct S5 {
738 int FirstBodySecondOutOfLine() { return 0; }
740 #elif defined(SECOND)
741 struct S5 {
742 int FirstBodySecondOutOfLine();
744 int S5::FirstBodySecondOutOfLine() { return 0; }
745 #else
746 S5 s5;
747 // 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}}
748 // expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}}
749 #endif
751 #if defined(FIRST)
752 struct S6 {
753 int FirstOutOfLineSecondBody();
755 int S6::FirstOutOfLineSecondBody() { return 0; }
756 #elif defined(SECOND)
757 struct S6 {
758 int FirstOutOfLineSecondBody() { return 0; }
760 #else
761 S6 s6;
762 // 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}}
763 // expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}}
764 #endif
766 #if defined(FIRST)
767 struct S7 {
768 int BothOutOfLine();
770 int S7::BothOutOfLine() { return 1; }
771 #elif defined(SECOND)
772 struct S7 {
773 int BothOutOfLine();
775 int S7::BothOutOfLine() { return 0; }
776 #else
777 S7 s7;
778 // expected-error@second.h:* {{'MethodBody::S7::BothOutOfLine' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
779 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
780 #endif
782 #if defined(FIRST)
783 struct S8 {
784 int FirstBodySecondOutOfLine() { return 0; }
786 #elif defined(SECOND)
787 struct S8 {
788 int FirstBodySecondOutOfLine();
790 int S8::FirstBodySecondOutOfLine() { return 1; }
791 #else
792 S8 s8;
793 // 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}}
794 // expected-note@first.h:* {{but in 'FirstModule' found method 'FirstBodySecondOutOfLine' with body}}
795 #endif
797 #if defined(FIRST)
798 struct S9 {
799 int FirstOutOfLineSecondBody();
801 int S9::FirstOutOfLineSecondBody() { return 1; }
802 #elif defined(SECOND)
803 struct S9 {
804 int FirstOutOfLineSecondBody() { return 0; }
806 #else
807 S9 s9;
808 // 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}}
809 // expected-note@second.h:* {{but in 'SecondModule' found method 'FirstOutOfLineSecondBody' with body}}
810 #endif
812 #if defined(FIRST)
813 struct S10 {
814 S10(int);
815 S10() = delete;
817 #elif defined(SECOND)
818 struct S10 {
819 S10(int);
820 S10();
822 #else
823 S10 s10(10);
824 // expected-error@first.h:* {{'MethodBody::S10' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is deleted}}
825 // expected-note@second.h:* {{but in 'SecondModule' found constructor is not deleted}}
826 #endif
828 #if defined(FIRST)
829 struct S11 {
830 S11() = default;
832 #elif defined(SECOND)
833 struct S11 {
834 S11();
836 #else
837 S11 s11;
838 // expected-error@first.h:* {{'MethodBody::S11' has different definitions in different modules; first difference is definition in module 'FirstModule' found constructor is defaulted}}
839 // expected-note@second.h:* {{but in 'SecondModule' found constructor is not defaulted}}
840 #endif
842 #define DECLS(CLASSNAME) \
843 CLASSNAME() = default; \
844 ~CLASSNAME() = delete; \
845 void A(); \
846 void B() { return; }; \
847 void C(); \
848 void D();
850 #define OUTOFLINEDEFS(CLASSNAME) \
851 void CLASSNAME::C() {} \
852 void CLASSNAME::D() { return; }
854 #if defined(FIRST) || defined(SECOND)
855 struct Valid1 {
856 DECLS(Valid1)
858 OUTOFLINEDEFS(Valid1)
859 #else
860 Valid1* v1;
861 #endif
863 #if defined(FIRST) || defined(SECOND)
864 struct Invalid1 {
865 DECLS(Invalid1)
866 ACCESS
868 OUTOFLINEDEFS(Invalid1)
869 #else
870 Invalid1* i1;
871 // expected-error@first.h:* {{'MethodBody::Invalid1' has different definitions in different modules; first difference is definition in module 'FirstModule' found public access specifier}}
872 // expected-note@second.h:* {{but in 'SecondModule' found private access specifier}}
873 #endif
874 #undef DECLS
875 } // namespace MethodBody
877 namespace Constructor {
878 #if defined(FIRST)
879 struct S1 {
880 S1() {}
881 void foo() {}
883 #elif defined(SECOND)
884 struct S1 {
885 void foo() {}
886 S1() {}
888 #else
889 S1 s1;
890 // expected-error@second.h:* {{'Constructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'foo'}}
891 // expected-note@first.h:* {{but in 'FirstModule' found constructor}}
892 #endif
894 #if defined(FIRST)
895 struct S2 {
896 S2(int) {}
897 S2(int, int) {}
899 #elif defined(SECOND)
900 struct S2 {
901 S2(int, int) {}
902 S2(int) {}
904 #else
905 S2* s2;
906 // 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}}
907 // expected-note@first.h:* {{but in 'FirstModule' found constructor that has 1 parameter}}
908 #endif
910 #define DECLS(CLASS) \
911 CLASS(int); \
912 CLASS(double); \
913 CLASS(int, int);
915 #if defined(FIRST) || defined(SECOND)
916 struct Valid1 {
917 DECLS(Valid1)
919 #else
920 Valid1* v1;
921 #endif
923 #if defined(FIRST) || defined(SECOND)
924 struct Invalid1 {
925 DECLS(Invalid1)
926 ACCESS
928 #else
929 Invalid1* i1;
930 // expected-error@second.h:* {{'Constructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
931 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
932 #endif
933 #undef DECLS
934 } // namespace Constructor
936 namespace Destructor {
937 #if defined(FIRST)
938 struct S1 {
939 ~S1() {}
940 S1() {}
942 #elif defined(SECOND)
943 struct S1 {
944 S1() {}
945 ~S1() {}
947 #else
948 S1 s1;
949 // expected-error@second.h:* {{'Destructor::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found constructor}}
950 // expected-note@first.h:* {{but in 'FirstModule' found destructor}}
951 #endif
953 #if defined(FIRST)
954 struct S2 {
955 virtual ~S2() {}
956 void foo() {}
958 #elif defined(SECOND)
959 struct S2 {
960 ~S2() {}
961 virtual void foo() {}
963 #else
964 S2 s2;
965 // expected-error@second.h:* {{'Destructor::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found destructor is not virtual}}
966 // expected-note@first.h:* {{but in 'FirstModule' found destructor is virtual}}
967 #endif
969 #if defined(FIRST) || defined(SECOND)
970 struct Valid1 {
971 ~Valid1();
973 #else
974 Valid1 v1;
975 #endif
977 #if defined(FIRST) || defined(SECOND)
978 struct Invalid1 {
979 ~Invalid1();
980 ACCESS
982 #else
983 Invalid1 i1;
984 // expected-error@second.h:* {{'Destructor::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
985 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
986 #endif
988 #if defined(FIRST) || defined(SECOND)
989 struct Valid2 {
990 virtual ~Valid2();
992 #else
993 Valid2 v2;
994 #endif
996 #if defined(FIRST) || defined(SECOND)
997 struct Invalid2 {
998 virtual ~Invalid2();
999 ACCESS
1001 #else
1002 Invalid2 i2;
1003 // expected-error@second.h:* {{'Destructor::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1004 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1005 #endif
1006 } // namespace Destructor
1008 namespace TypeDef {
1009 #if defined(FIRST)
1010 struct S1 {
1011 typedef int a;
1013 #elif defined(SECOND)
1014 struct S1 {
1015 typedef double a;
1017 #else
1018 S1 s1;
1019 // expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
1020 // expected-note@second.h:* {{declaration of 'a' does not match}}
1021 #endif
1023 #if defined(FIRST)
1024 struct S2 {
1025 typedef int a;
1027 #elif defined(SECOND)
1028 struct S2 {
1029 typedef int b;
1031 #else
1032 S2 s2;
1033 // expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
1034 // expected-note@second.h:* {{definition has no member 'a'}}
1035 #endif
1037 #if defined(FIRST)
1038 typedef int T;
1039 struct S3 {
1040 typedef T a;
1042 #elif defined(SECOND)
1043 typedef double T;
1044 struct S3 {
1045 typedef T a;
1047 #else
1048 S3 s3;
1049 // FIXME: We should reject the merge of `S3` due to the inconsistent definition of `T`.
1050 #endif
1052 #if defined(FIRST)
1053 struct S4 {
1054 typedef int a;
1055 typedef int b;
1057 #elif defined(SECOND)
1058 struct S4 {
1059 typedef int b;
1060 typedef int a;
1062 #else
1063 S4 s4;
1064 // expected-error@second.h:* {{'TypeDef::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found typedef name 'b'}}
1065 // expected-note@first.h:* {{but in 'FirstModule' found typedef name 'a'}}
1066 #endif
1068 #if defined(FIRST)
1069 struct S5 {
1070 typedef int a;
1071 typedef int b;
1072 int x;
1074 #elif defined(SECOND)
1075 struct S5 {
1076 int x;
1077 typedef int b;
1078 typedef int a;
1080 #else
1081 S5 s5;
1082 // expected-error@second.h:* {{'TypeDef::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
1083 // expected-note@first.h:* {{but in 'FirstModule' found typedef}}
1084 #endif
1086 #if defined(FIRST)
1087 typedef float F;
1088 struct S6 {
1089 typedef int a;
1090 typedef F b;
1092 #elif defined(SECOND)
1093 struct S6 {
1094 typedef int a;
1095 typedef float b;
1097 #else
1098 S6 s6;
1099 // 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'}}
1100 // expected-note@first.h:* {{but in 'FirstModule' found typedef 'b' with different underlying type 'F' (aka 'float')}}
1101 #endif
1103 #define DECLS \
1104 typedef int A; \
1105 typedef double B; \
1106 typedef I C;
1108 #if defined(FIRST) || defined(SECOND)
1109 typedef int I;
1110 #endif
1112 #if defined(FIRST) || defined(SECOND)
1113 struct Valid1 {
1114 DECLS
1116 #else
1117 Valid1 v1;
1118 #endif
1120 #if defined(FIRST) || defined(SECOND)
1121 struct Invalid1 {
1122 DECLS
1123 ACCESS
1125 #else
1126 Invalid1 i1;
1127 // expected-error@second.h:* {{'TypeDef::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1128 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1129 #endif
1130 #undef DECLS
1131 } // namespace TypeDef
1133 namespace Using {
1134 #if defined(FIRST)
1135 struct S1 {
1136 using a = int;
1138 #elif defined(SECOND)
1139 struct S1 {
1140 using a = double;
1142 #else
1143 S1 s1;
1144 // expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
1145 // expected-note@second.h:* {{declaration of 'a' does not match}}
1146 #endif
1148 #if defined(FIRST)
1149 struct S2 {
1150 using a = int;
1152 #elif defined(SECOND)
1153 struct S2 {
1154 using b = int;
1156 #else
1157 S2 s2;
1158 // expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
1159 // expected-note@second.h:* {{definition has no member 'a'}}
1160 #endif
1162 #if defined(FIRST)
1163 typedef int T;
1164 struct S3 {
1165 using a = T;
1167 #elif defined(SECOND)
1168 typedef double T;
1169 struct S3 {
1170 using a = T;
1172 #else
1173 S3 s3;
1174 // FIXME: We should reject the merge of `S3` due to the inconsistent definition of `T`.
1175 #endif
1177 #if defined(FIRST)
1178 struct S4 {
1179 using a = int;
1180 using b = int;
1182 #elif defined(SECOND)
1183 struct S4 {
1184 using b = int;
1185 using a = int;
1187 #else
1188 S4 s4;
1189 // expected-error@second.h:* {{'Using::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found type alias name 'b'}}
1190 // expected-note@first.h:* {{but in 'FirstModule' found type alias name 'a'}}
1191 #endif
1193 #if defined(FIRST)
1194 struct S5 {
1195 using a = int;
1196 using b = int;
1197 int x;
1199 #elif defined(SECOND)
1200 struct S5 {
1201 int x;
1202 using b = int;
1203 using a = int;
1205 #else
1206 S5 s5;
1207 // expected-error@second.h:* {{'Using::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
1208 // expected-note@first.h:* {{but in 'FirstModule' found type alias}}
1209 #endif
1211 #if defined(FIRST)
1212 typedef float F;
1213 struct S6 {
1214 using a = int;
1215 using b = F;
1217 #elif defined(SECOND)
1218 struct S6 {
1219 using a = int;
1220 using b = float;
1222 #else
1223 S6 s6;
1224 // 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'}}
1225 // expected-note@first.h:* {{but in 'FirstModule' found type alias 'b' with different underlying type 'F' (aka 'float')}}
1226 #endif
1228 #if defined(FIRST) || defined(SECOND)
1229 using I = int;
1230 #endif
1232 #define DECLS \
1233 using A = int; \
1234 using B = double; \
1235 using C = I;
1237 #if defined(FIRST) || defined(SECOND)
1238 struct Valid1 {
1239 DECLS
1241 #else
1242 Valid1 v1;
1243 #endif
1245 #if defined(FIRST) || defined(SECOND)
1246 struct Invalid1 {
1247 DECLS
1248 ACCESS
1250 #else
1251 Invalid1 i1;
1252 // expected-error@second.h:* {{'Using::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1253 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1254 #endif
1255 #undef DECLS
1256 } // namespace Using
1258 namespace RecordType {
1259 #if defined(FIRST)
1260 struct B1 {};
1261 struct S1 {
1262 B1 x;
1264 #elif defined(SECOND)
1265 struct A1 {};
1266 struct S1 {
1267 A1 x;
1269 #else
1270 S1 s1;
1271 // expected-error@first.h:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
1272 // expected-note@second.h:* {{declaration of 'x' does not match}}
1273 #endif
1275 #define DECLS \
1276 Foo F;
1278 #if defined(FIRST) || defined(SECOND)
1279 struct Foo {};
1280 #endif
1282 #if defined(FIRST) || defined(SECOND)
1283 struct Valid1 {
1284 DECLS
1286 #else
1287 Valid1 v1;
1288 #endif
1290 #if defined(FIRST) || defined(SECOND)
1291 struct Invalid1 {
1292 DECLS
1293 ACCESS
1295 #else
1296 Invalid1 i1;
1297 // expected-error@second.h:* {{'RecordType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1298 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1299 #endif
1300 #undef DECLS
1301 } // namespace RecordType
1303 namespace DependentType {
1304 #if defined(FIRST)
1305 template <class T>
1306 class S1 {
1307 typename T::typeA x;
1309 #elif defined(SECOND)
1310 template <class T>
1311 class S1 {
1312 typename T::typeB x;
1314 #else
1315 template<class T>
1316 using U1 = S1<T>;
1317 // expected-error@first.h:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
1318 // expected-note@second.h:* {{declaration of 'x' does not match}}
1319 #endif
1321 #define DECLS \
1322 typename T::typeA x;
1324 #if defined(FIRST) || defined(SECOND)
1325 template <class T>
1326 struct Valid1 {
1327 DECLS
1329 #else
1330 template <class T>
1331 using V1 = Valid1<T>;
1332 #endif
1334 #if defined(FIRST) || defined(SECOND)
1335 template <class T>
1336 struct Invalid1 {
1337 DECLS
1338 ACCESS
1340 #else
1341 template <class T>
1342 using I1 = Invalid1<T>;
1343 // expected-error@second.h:* {{'DependentType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1344 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1345 #endif
1346 #undef DECLS
1347 } // namespace DependentType
1349 namespace ElaboratedType {
1350 #if defined(FIRST)
1351 namespace N1 { using type = double; }
1352 struct S1 {
1353 N1::type x;
1355 #elif defined(SECOND)
1356 namespace N1 { using type = int; }
1357 struct S1 {
1358 N1::type x;
1360 #else
1361 S1 s1;
1362 #endif
1364 #define DECLS \
1365 NS::type x;
1367 #if defined(FIRST) || defined(SECOND)
1368 namespace NS { using type = float; }
1369 #endif
1371 #if defined(FIRST) || defined(SECOND)
1372 struct Valid1 {
1373 DECLS
1375 #else
1376 Valid1 v1;
1377 #endif
1379 #if defined(FIRST) || defined(SECOND)
1380 struct Invalid1 {
1381 DECLS
1382 ACCESS
1384 #else
1385 Invalid1 i1;
1386 // expected-error@second.h:* {{'ElaboratedType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1387 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1388 #endif
1389 #undef DECLS
1390 } // namespace ElaboratedType
1392 namespace Enum {
1393 #if defined(FIRST)
1394 enum A1 {};
1395 struct S1 {
1396 A1 x;
1398 #elif defined(SECOND)
1399 enum A2 {};
1400 struct S1 {
1401 A2 x;
1403 #else
1404 S1 s1;
1405 // expected-error@first.h:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
1406 // expected-note@second.h:* {{declaration of 'x' does not match}}
1407 #endif
1409 #define DECLS \
1410 E e = E1;
1412 #if defined(FIRST) || defined(SECOND)
1413 enum E { E1, E2 };
1414 #endif
1416 #if defined(FIRST) || defined(SECOND)
1417 struct Valid1 {
1418 DECLS
1420 #else
1421 Valid1 v1;
1422 #endif
1424 #if defined(FIRST) || defined(SECOND)
1425 struct Invalid1 {
1426 DECLS
1427 ACCESS
1429 #else
1430 Invalid1 i1;
1431 // expected-error@second.h:* {{'Enum::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1432 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1433 #endif
1434 #undef DECLS
1437 namespace NestedNamespaceSpecifier {
1438 #if defined(FIRST)
1439 namespace LevelA1 {
1440 using Type = int;
1443 struct S1 {
1444 LevelA1::Type x;
1446 # elif defined(SECOND)
1447 namespace LevelB1 {
1448 namespace LevelC1 {
1449 using Type = int;
1453 struct S1 {
1454 LevelB1::LevelC1::Type x;
1456 #else
1457 S1 s1;
1458 // 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')}}
1459 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
1460 #endif
1462 #if defined(FIRST)
1463 namespace LevelA2 { using Type = int; }
1464 struct S2 {
1465 LevelA2::Type x;
1467 # elif defined(SECOND)
1468 struct S2 {
1469 int x;
1471 #else
1472 S2 s2;
1473 // 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'}}
1474 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
1475 #endif
1477 namespace LevelA3 { using Type = int; }
1478 namespace LevelB3 { using Type = int; }
1479 #if defined(FIRST)
1480 struct S3 {
1481 LevelA3::Type x;
1483 # elif defined(SECOND)
1484 struct S3 {
1485 LevelB3::Type x;
1487 #else
1488 S3 s3;
1489 // 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')}}
1490 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
1491 #endif
1493 #if defined(FIRST)
1494 struct TA4 { using Type = int; };
1495 struct S4 {
1496 TA4::Type x;
1498 # elif defined(SECOND)
1499 struct TB4 { using Type = int; };
1500 struct S4 {
1501 TB4::Type x;
1503 #else
1504 S4 s4;
1505 // 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')}}
1506 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
1507 #endif
1509 #if defined(FIRST)
1510 struct T5 { using Type = int; };
1511 struct S5 {
1512 T5::Type x;
1514 # elif defined(SECOND)
1515 namespace T5 { using Type = int; };
1516 struct S5 {
1517 T5::Type x;
1519 #else
1520 S5 s5;
1521 // 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')}}
1522 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
1523 #endif
1525 #if defined(FIRST)
1526 namespace N6 {using I = int;}
1527 struct S6 {
1528 NestedNamespaceSpecifier::N6::I x;
1530 # elif defined(SECOND)
1531 using I = int;
1532 struct S6 {
1533 ::NestedNamespaceSpecifier::I x;
1535 #else
1536 S6 s6;
1537 // 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')}}
1538 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
1539 #endif
1541 #if defined(FIRST)
1542 template <class T, class U>
1543 class S7 {
1544 typename T::type *x = {};
1545 int z = x->T::foo();
1547 #elif defined(SECOND)
1548 template <class T, class U>
1549 class S7 {
1550 typename T::type *x = {};
1551 int z = x->U::foo();
1553 #else
1554 template <class T, class U>
1555 using U7 = S7<T, U>;
1556 // 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}}
1557 // expected-note@first.h:* {{but in 'FirstModule' found field 'z' with a different initializer}}
1558 #endif
1560 #if defined(FIRST)
1561 template <class T>
1562 class S8 {
1563 int x = T::template X<int>::value;
1565 #elif defined(SECOND)
1566 template <class T>
1567 class S8 {
1568 int x = T::template Y<int>::value;
1570 #else
1571 template <class T>
1572 using U8 = S8<T>;
1573 // 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}}
1574 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
1575 #endif
1577 #if defined(FIRST)
1578 namespace N9 { using I = int; }
1579 namespace O9 = N9;
1580 struct S9 {
1581 O9::I x;
1583 #elif defined(SECOND)
1584 namespace N9 { using I = int; }
1585 namespace P9 = N9;
1586 struct S9 {
1587 P9::I x;
1589 #else
1590 S9 s9;
1591 // 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')}}
1592 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
1593 #endif
1595 namespace N10 {
1596 #if defined(FIRST)
1597 inline namespace A { struct X {}; }
1598 struct S10 {
1599 A::X x;
1601 #elif defined(SECOND)
1602 inline namespace B { struct X {}; }
1603 struct S10 {
1604 B::X x;
1606 #else
1607 S10 s10;
1608 // expected-error@second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
1609 // expected-note@first.h:* {{declaration of 'x' does not match}}
1610 #endif
1613 #define DECLS \
1614 NS1::Type a; \
1615 NS1::NS2::Type b; \
1616 NS1::S c; \
1617 NS3::Type d;
1619 #if defined(FIRST) || defined(SECOND)
1620 namespace NS1 {
1621 using Type = int;
1622 namespace NS2 {
1623 using Type = double;
1625 struct S {};
1627 namespace NS3 = NS1;
1628 #endif
1630 #if defined(FIRST) || defined(SECOND)
1631 struct Valid1 {
1632 DECLS
1634 #else
1635 Valid1 v1;
1636 #endif
1638 #if defined(FIRST) || defined(SECOND)
1639 struct Invalid1 {
1640 DECLS
1641 ACCESS
1643 #else
1644 Invalid1 i1;
1645 // expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1646 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1647 #endif
1648 #undef DECLS
1650 #define DECLS \
1651 typename T::type *x = {}; \
1652 int y = x->T::foo(); \
1653 int z = U::template X<int>::value;
1655 #if defined(FIRST) || defined(SECOND)
1656 template <class T, class U>
1657 struct Valid2 {
1658 DECLS
1660 #else
1661 template <class T, class U>
1662 using V2 = Valid2<T, U>;
1663 #endif
1665 #if defined(FIRST) || defined(SECOND)
1666 template <class T, class U>
1667 struct Invalid2 {
1668 DECLS
1669 ACCESS
1671 #else
1672 template <class T, class U>
1673 using I2 = Invalid2<T, U>;
1674 // expected-error@second.h:* {{'NestedNamespaceSpecifier::Invalid2' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1675 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1676 #endif
1677 #undef DECLS
1678 } // namespace NestedNamespaceSpecifier
1680 namespace TemplateSpecializationType {
1681 #if defined(FIRST)
1682 template <class T1> struct U1 {};
1683 struct S1 {
1684 U1<int> u;
1686 #elif defined(SECOND)
1687 template <class T1, class T2> struct U1 {};
1688 struct S1 {
1689 U1<int, int> u;
1691 #else
1692 S1 s1;
1693 // expected-error@first.h:* {{'TemplateSpecializationType::S1::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S1' in module 'SecondModule'}}
1694 // expected-note@second.h:* {{declaration of 'u' does not match}}
1695 #endif
1697 #if defined(FIRST)
1698 template <class T1> struct U2 {};
1699 struct S2 {
1700 U2<int> u;
1702 #elif defined(SECOND)
1703 template <class T1> struct V1 {};
1704 struct S2 {
1705 V1<int> u;
1707 #else
1708 S2 s2;
1709 // expected-error@first.h:* {{'TemplateSpecializationType::S2::u' from module 'FirstModule' is not present in definition of 'TemplateSpecializationType::S2' in module 'SecondModule'}}
1710 // expected-note@second.h:* {{declaration of 'u' does not match}}
1711 #endif
1713 #define DECLS \
1714 OneTemplateArg<int> x; \
1715 OneTemplateArg<double> y; \
1716 OneTemplateArg<char *> z; \
1717 TwoTemplateArgs<int, int> a; \
1718 TwoTemplateArgs<double, float> b; \
1719 TwoTemplateArgs<short *, char> c;
1721 #if defined(FIRST) || defined(SECOND)
1722 template <class T> struct OneTemplateArg {};
1723 template <class T, class U> struct TwoTemplateArgs {};
1724 #endif
1726 #if defined(FIRST) || defined(SECOND)
1727 struct Valid1 {
1728 DECLS
1730 #else
1731 Valid1 v1;
1732 #endif
1734 #if defined(FIRST) || defined(SECOND)
1735 struct Invalid1 {
1736 DECLS
1737 ACCESS
1739 #else
1740 Invalid1 i1;
1741 // expected-error@second.h:* {{'TemplateSpecializationType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1742 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
1743 #endif
1744 #undef DECLS
1745 } // namespace TemplateSpecializationType
1747 namespace TemplateArgument {
1748 #if defined(FIRST)
1749 template <class> struct U1{};
1750 struct S1 {
1751 U1<int> x;
1753 #elif defined(SECOND)
1754 template <int> struct U1{};
1755 struct S1 {
1756 U1<1> x;
1758 #else
1759 S1 s1;
1760 // expected-error@first.h:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
1761 // expected-note@second.h:* {{declaration of 'x' does not match}}
1762 #endif
1764 #if defined(FIRST)
1765 template <int> struct U2{};
1766 struct S2 {
1767 using T = U2<2>;
1769 #elif defined(SECOND)
1770 template <int> struct U2{};
1771 struct S2 {
1772 using T = U2<(2)>;
1774 #else
1775 S2 s2;
1776 // 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)>'}}
1777 // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U2<2>'}}
1778 #endif
1780 #if defined(FIRST)
1781 template <int> struct U3{};
1782 struct S3 {
1783 using T = U3<2>;
1785 #elif defined(SECOND)
1786 template <int> struct U3{};
1787 struct S3 {
1788 using T = U3<1 + 1>;
1790 #else
1791 S3 s3;
1792 // 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>'}}
1793 // expected-note@first.h:* {{but in 'FirstModule' found type alias 'T' with different underlying type 'U3<2>'}}
1794 #endif
1796 #if defined(FIRST)
1797 template<class> struct T4a {};
1798 template <template <class> class T> struct U4 {};
1799 struct S4 {
1800 U4<T4a> x;
1802 #elif defined(SECOND)
1803 template<class> struct T4b {};
1804 template <template <class> class T> struct U4 {};
1805 struct S4 {
1806 U4<T4b> x;
1808 #else
1809 S4 s4;
1810 // expected-error@first.h:* {{'TemplateArgument::S4::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S4' in module 'SecondModule'}}
1811 // expected-note@second.h:* {{declaration of 'x' does not match}}
1812 #endif
1814 #if defined(FIRST)
1815 template <class T> struct U5 {};
1816 struct S5 {
1817 U5<int> x;
1819 #elif defined(SECOND)
1820 template <class T> struct U5 {};
1821 struct S5 {
1822 U5<short> x;
1824 #else
1825 S5 s5;
1826 // expected-error@first.h:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}}
1827 // expected-note@second.h:* {{declaration of 'x' does not match}}
1828 #endif
1830 #if defined(FIRST)
1831 template <class T> struct U6 {};
1832 struct S6 {
1833 U6<int> x;
1834 U6<short> y;
1836 #elif defined(SECOND)
1837 template <class T> struct U6 {};
1838 struct S6 {
1839 U6<short> y;
1840 U6<int> x;
1842 #else
1843 S6 s6;
1844 // expected-error@second.h:* {{'TemplateArgument::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
1845 // expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
1846 #endif
1848 #if defined(FIRST)
1849 struct S7 {
1850 template<int> void run() {}
1851 template<> void run<1>() {}
1853 #elif defined(SECOND)
1854 struct S7 {
1855 template<int> void run() {}
1856 void run() {}
1858 #else
1859 S7 s7;
1860 // 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}}
1861 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with template arguments}}
1862 #endif
1864 #if defined(FIRST)
1865 struct S8 {
1866 static int a, b;
1867 template<int&> void run() {}
1868 template<int&, int&> void run() {}
1869 template<> void run<a>() {}
1871 #elif defined(SECOND)
1872 struct S8 {
1873 static int a, b;
1874 template<int&> void run() {}
1875 template<int&, int&> void run() {}
1876 template<> void run<a, b>() {}
1878 #else
1879 S8 s8;
1880 // 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}}
1881 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 1 template argument}}
1882 #endif
1884 #if defined(FIRST)
1885 struct S9 {
1886 static int a, b;
1887 template<int&> void run() {}
1888 template<> void run<a>() {}
1890 #elif defined(SECOND)
1891 struct S9 {
1892 static int a, b;
1893 template<int&> void run() {}
1894 template<> void run<b>() {}
1896 #else
1897 S9 s9;
1898 // 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}}
1899 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 1st template argument}}
1900 #endif
1902 #if defined(FIRST)
1903 struct S10 {
1904 static int a, b;
1905 template<int, int&...> void run() {}
1906 template<> void run<1, a>() {}
1908 #elif defined(SECOND)
1909 struct S10 {
1910 static int a, b;
1911 template<int, int&...> void run() {}
1912 template<> void run<1, b>() {}
1914 #else
1915 S10 s10;
1916 // 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}}
1917 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 'a' for 2nd template argument}}
1918 #endif
1920 #if defined(FIRST)
1921 struct S11 {
1922 static int a, b;
1923 template<int, int&...> void run() {}
1924 template<> void run<1, a>() {}
1926 #elif defined(SECOND)
1927 struct S11 {
1928 static int a, b;
1929 template<int, int&...> void run() {}
1930 template<> void run<1, a, a>() {}
1932 #else
1933 S11 s11;
1934 // 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}}
1935 // expected-note@first.h:* {{but in 'FirstModule' found method 'run' with 2 template arguments}}
1936 #endif
1938 #if defined(FIRST)
1939 struct S12 {
1940 template <int> void f(){};
1941 template <> void f<1>(){};
1943 #elif defined(SECOND)
1944 struct S12 {
1945 template <int> void f(){};
1946 template <> void f<2>(){};
1948 #else
1949 S12 s12;
1950 // expected-error@second.h:* {{'TemplateArgument::S12' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 2 for 1st template argument}}
1951 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 1 for 1st template argument}}
1952 #endif
1954 #if defined(FIRST)
1955 struct S13 {
1956 template <int> void f(){};
1957 template <> void f<10>(){};
1959 #elif defined(SECOND)
1960 struct S13 {
1961 template <int> void f(){};
1962 template <> void f<10>(){};
1964 #else
1965 S13 s13;
1966 #endif
1968 #if defined(FIRST)
1969 struct S14 {
1970 template <bool, bool> void f(){};
1971 template <> void f<true, false>(){};
1973 #elif defined(SECOND)
1974 struct S14 {
1975 template <bool, bool> void f(){};
1976 template <> void f<false, true>(){};
1978 #else
1979 S14 s14;
1980 // expected-error@second.h:* {{'TemplateArgument::S14' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 0 for 1st template argument}}
1981 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 1 for 1st template argument}}
1982 #endif
1984 #if defined(FIRST)
1985 struct S15 {
1986 template <bool, bool> void f(){};
1987 template <> void f<true, true>(){};
1989 #elif defined(SECOND)
1990 struct S15 {
1991 template <bool, bool> void f(){};
1992 template <> void f<true, true>(){};
1994 #else
1995 S15 s15;
1996 #endif
1998 #if defined(FIRST)
1999 struct S16 {
2000 template <int *> void f(){};
2001 template <> void f<nullptr>(){};
2003 #elif defined(SECOND)
2004 struct S16 {
2005 template <int *> void f(){};
2006 template <> void f<nullptr>(){};
2008 #else
2009 S16 s16;
2010 #endif
2012 #if defined(FIRST)
2013 struct S17 {
2014 static int x;
2015 template <int *> void f(){};
2016 template <> void f<&x>(){};
2018 #elif defined(SECOND)
2019 struct S17 {
2020 static int x;
2021 template <int *> void f(){};
2022 template <> void f<nullptr>(){};
2024 #else
2025 S17 s17;
2026 // expected-error@second.h:* {{'TemplateArgument::S17' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with nullptr for 1st template argument}}
2027 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 'x' for 1st template argument}}
2028 #endif
2030 #if defined(FIRST)
2031 struct S18 {
2032 static int x;
2033 template <int *> void f(){};
2034 template <> void f<&x>(){};
2036 #elif defined(SECOND)
2037 struct S18 {
2038 static int x;
2039 template <int *> void f(){};
2040 template <> void f<&x>(){};
2042 #else
2043 S18 s18;
2044 #endif
2046 #if defined(FIRST)
2047 struct S19 {
2048 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1);
2049 template <_BitInt(128)> void f(){};
2050 template <> void f<x + x>(){};
2052 #elif defined(SECOND)
2053 struct S19 {
2054 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1);
2055 template <_BitInt(128)> void f(){};
2056 template <> void f<x + x>(){};
2058 #else
2059 S19 s19;
2060 #endif
2062 #if defined(FIRST)
2063 struct S20 {
2064 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1);
2065 template <_BitInt(128)> void f(){};
2066 template <> void f<x + x>(){};
2068 #elif defined(SECOND)
2069 struct S20 {
2070 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1);
2071 template <_BitInt(128)> void f(){};
2072 template <> void f<x>(){};
2074 #else
2075 S20 s20;
2076 // expected-error@second.h:* {{'TemplateArgument::S20' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'f' with 18446744073709551615 for 1st template argument}}
2077 // expected-note@first.h:* {{but in 'FirstModule' found method 'f' with 36893488147419103230 for 1st template argument}}
2078 #endif
2080 #if defined(FIRST)
2081 struct S21 {
2082 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1);
2083 template <_BitInt(128)> void f(){};
2084 template <> void f<x + 0>(){};
2086 #elif defined(SECOND)
2087 struct S21 {
2088 static constexpr _BitInt(128) x = static_cast<_BitInt(128)>((unsigned long long)-1);
2089 template <_BitInt(128)> void f(){};
2090 template <> void f<(unsigned long long)-1>(){};
2092 #else
2093 S21 s21;
2094 #endif
2096 #define DECLS \
2097 OneClass<int> a; \
2098 OneInt<1> b; \
2099 using c = OneClass<float>; \
2100 using d = OneInt<2>; \
2101 using e = OneInt<2 + 2>; \
2102 OneTemplateClass<OneClass> f; \
2103 OneTemplateInt<OneInt> g; \
2104 static int i1, i2; \
2105 template <int &> \
2106 void Function() {} \
2107 template <int &, int &> \
2108 void Function() {} \
2109 template <> \
2110 void Function<i1>() {} \
2111 template <> \
2112 void Function<i2>() {} \
2113 template <> \
2114 void Function<i1, i2>() {} \
2115 template <> \
2116 void Function<i2, i1>() {}
2118 #if defined(FIRST) || defined(SECOND)
2119 template <class> struct OneClass{};
2120 template <int> struct OneInt{};
2121 template <template <class> class> struct OneTemplateClass{};
2122 template <template <int> class> struct OneTemplateInt{};
2123 #endif
2125 #if defined(FIRST) || defined(SECOND)
2126 struct Valid1 {
2127 DECLS
2129 #else
2130 Valid1 v1;
2131 #endif
2133 #if defined(FIRST) || defined(SECOND)
2134 struct Invalid1 {
2135 DECLS
2136 ACCESS
2138 #else
2139 Invalid1 i1;
2140 // expected-error@second.h:* {{'TemplateArgument::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2141 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2142 #endif
2143 #undef DECLS
2144 } // namespace TemplateArgument
2146 namespace TemplateTypeParmType {
2147 #if defined(FIRST)
2148 template <class T1, class T2>
2149 struct S1 {
2150 T1 x;
2152 #elif defined(SECOND)
2153 template <class T1, class T2>
2154 struct S1 {
2155 T2 x;
2157 #else
2158 using TemplateTypeParmType::S1;
2159 // expected-error@first.h:* {{'TemplateTypeParmType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T1, T2>' in module 'SecondModule'}}
2160 // expected-note@second.h:* {{declaration of 'x' does not match}}
2161 #endif
2163 #if defined(FIRST)
2164 template <int ...Ts>
2165 struct U2 {};
2166 template <int T, int U>
2167 class S2 {
2168 typedef U2<U, T> type;
2169 type x;
2171 #elif defined(SECOND)
2172 template <int ...Ts>
2173 struct U2 {};
2174 template <int T, int U>
2175 class S2 {
2176 typedef U2<T, U> type;
2177 type x;
2179 #else
2180 using TemplateTypeParmType::S2;
2181 // expected-error@first.h:* {{'TemplateTypeParmType::S2::x' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
2182 // expected-note@second.h:* {{declaration of 'x' does not match}}
2183 // expected-error@first.h:* {{'TemplateTypeParmType::S2::type' from module 'FirstModule' is not present in definition of 'S2<T, U>' in module 'SecondModule'}}
2184 // expected-note@second.h:* {{declaration of 'type' does not match}}
2185 #endif
2187 #define DECLS \
2188 T t; \
2189 U u; \
2190 ParameterPack<T> a; \
2191 ParameterPack<T, U> b; \
2192 ParameterPack<U> c; \
2193 ParameterPack<U, T> d;
2195 #if defined(FIRST) || defined(SECOND)
2196 template <class ...Ts> struct ParameterPack {};
2197 #endif
2199 #if defined(FIRST) || defined(SECOND)
2200 template <class T, class U>
2201 struct Valid1 {
2202 DECLS
2204 #else
2205 using TemplateTypeParmType::Valid1;
2206 #endif
2208 #if defined(FIRST) || defined(SECOND)
2209 template <class T, class U>
2210 struct Invalid1 {
2211 DECLS
2212 ACCESS
2214 #else
2215 using TemplateTypeParmType::Invalid1;
2216 // expected-error@second.h:* {{'TemplateTypeParmType::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2217 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2218 #endif
2219 #undef DECLS
2220 } // namespace TemplateTypeParmType
2222 namespace VarDecl {
2223 #if defined(FIRST)
2224 struct S1 {
2225 static int x;
2226 static int y;
2228 #elif defined(SECOND)
2229 struct S1 {
2230 static int y;
2231 static int x;
2233 #else
2234 S1 s1;
2235 // 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'}}
2236 // expected-note@first.h:* {{but in 'FirstModule' found data member with name 'x'}}
2237 #endif
2239 #if defined(FIRST)
2240 struct S2 {
2241 static int x;
2243 #elif defined(SECOND)
2244 using I = int;
2245 struct S2 {
2246 static I x;
2248 #else
2249 S2 s2;
2250 // 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 'I' (aka 'int')}}
2251 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with different type 'int'}}
2252 #endif
2254 #if defined(FIRST)
2255 struct S3 {
2256 static const int x = 1;
2258 #elif defined(SECOND)
2259 struct S3 {
2260 static const int x;
2262 #else
2263 S3 s3;
2264 // 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}}
2265 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' without an initializer}}
2266 #endif
2268 #if defined(FIRST)
2269 struct S4 {
2270 static const int x = 1;
2272 #elif defined(SECOND)
2273 struct S4 {
2274 static const int x = 2;
2276 #else
2277 S4 s4;
2278 // 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}}
2279 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' with a different initializer}}
2280 #endif
2282 #if defined(FIRST)
2283 struct S5 {
2284 static const int x = 1;
2286 #elif defined(SECOND)
2287 struct S5 {
2288 static constexpr int x = 1;
2290 #else
2291 S5 s5;
2292 // 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}}
2293 // expected-note@first.h:* {{but in 'FirstModule' found data member 'x' is constexpr}}
2294 #endif
2296 #if defined(FIRST)
2297 struct S6 {
2298 static const int x = 1;
2300 #elif defined(SECOND)
2301 struct S6 {
2302 static const int y = 1;
2304 #else
2305 S6 s6;
2306 // expected-error@first.h:* {{'VarDecl::S6::x' from module 'FirstModule' is not present in definition of 'VarDecl::S6' in module 'SecondModule'}}
2307 // expected-note@second.h:* {{definition has no member 'x'}}
2308 #endif
2310 #if defined(FIRST)
2311 struct S7 {
2312 static const int x = 1;
2314 #elif defined(SECOND)
2315 struct S7 {
2316 static const unsigned x = 1;
2318 #else
2319 S7 s7;
2320 // expected-error@first.h:* {{'VarDecl::S7::x' from module 'FirstModule' is not present in definition of 'VarDecl::S7' in module 'SecondModule'}}
2321 // expected-note@second.h:* {{declaration of 'x' does not match}}
2322 #endif
2324 #if defined(FIRST)
2325 struct S8 {
2326 public:
2327 static const int x = 1;
2329 #elif defined(SECOND)
2330 struct S8 {
2331 static const int x = 1;
2332 public:
2334 #else
2335 S8 s8;
2336 // expected-error@second.h:* {{'VarDecl::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found data member}}
2337 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2338 #endif
2340 #if defined(FIRST)
2341 struct S9 {
2342 static const int x = 1;
2344 #elif defined(SECOND)
2345 struct S9 {
2346 static int x;
2348 #else
2349 S9 s9;
2350 // expected-error@first.h:* {{'VarDecl::S9::x' from module 'FirstModule' is not present in definition of 'VarDecl::S9' in module 'SecondModule'}}
2351 // expected-note@second.h:* {{declaration of 'x' does not match}}
2352 #endif
2354 #define DECLS \
2355 static int a; \
2356 static I b; \
2357 static const int c = 1; \
2358 static constexpr int d = 5;
2360 #if defined(FIRST) || defined(SECOND)
2361 using I = int;
2362 #endif
2364 #if defined(FIRST) || defined(SECOND)
2365 struct Valid1 {
2366 DECLS
2368 #else
2369 Valid1 v1;
2370 #endif
2372 #if defined(FIRST) || defined(SECOND)
2373 struct Invalid1 {
2374 DECLS
2375 ACCESS
2377 #else
2378 Invalid1 i1;
2379 // expected-error@second.h:* {{'VarDecl::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2380 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2381 #endif
2382 #undef DECLS
2383 } // namespace VarDecl
2385 namespace Friend {
2386 #if defined(FIRST)
2387 struct T1 {};
2388 struct S1 {
2389 friend class T1;
2391 #elif defined(SECOND)
2392 struct T1 {};
2393 struct S1 {
2394 friend T1;
2396 #else
2397 S1 s1;
2398 // expected-error@second.h:* {{'Friend::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'T1'}}
2399 // expected-note@first.h:* {{but in 'FirstModule' found friend 'class T1'}}
2400 #endif
2402 #if defined(FIRST)
2403 struct T2 {};
2404 struct S2 {
2405 friend class T2;
2407 #elif defined(SECOND)
2408 struct T2 {};
2409 struct S2 {
2410 friend struct T2;
2412 #else
2413 S2 s2;
2414 // expected-error@second.h:* {{'Friend::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'struct T2'}}
2415 // expected-note@first.h:* {{but in 'FirstModule' found friend 'class T2'}}
2416 #endif
2418 #if defined(FIRST)
2419 struct T4 {};
2420 struct S4 {
2421 friend T4;
2423 #elif defined(SECOND)
2424 struct S4 {
2425 friend void T4();
2427 #else
2428 S4 s4;
2429 // expected-error@second.h:* {{'Friend::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function}}
2430 // expected-note@first.h:* {{but in 'FirstModule' found friend class}}
2431 #endif
2433 #if defined(FIRST)
2434 struct S5 {
2435 friend void T5a();
2437 #elif defined(SECOND)
2438 struct S5 {
2439 friend void T5b();
2441 #else
2442 S5 s5;
2443 // expected-error@second.h:* {{'Friend::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend function 'T5b'}}
2444 // expected-note@first.h:* {{but in 'FirstModule' found friend function 'T5a'}}
2445 #endif
2447 #define DECLS \
2448 friend class FriendA; \
2449 friend struct FriendB; \
2450 friend FriendC; \
2451 friend void Function();
2453 #if defined(FIRST) || defined(SECOND)
2454 class FriendA {};
2455 class FriendB {};
2456 class FriendC {};
2457 #endif
2459 #if defined(FIRST) || defined(SECOND)
2460 struct Valid1 {
2461 DECLS
2463 #else
2464 Valid1 v1;
2465 #endif
2467 #if defined(FIRST) || defined(SECOND)
2468 struct Invalid1 {
2469 DECLS
2470 ACCESS
2472 #else
2473 Invalid1 i1;
2474 // expected-error@second.h:* {{'Friend::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2475 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2476 #endif
2477 #undef DECLS
2478 } // namespace Friend
2480 namespace TemplateParameters {
2481 #if defined(FIRST)
2482 template <class A>
2483 struct S1 {};
2484 #elif defined(SECOND)
2485 template <class B>
2486 struct S1 {};
2487 #else
2488 using TemplateParameters::S1;
2489 // expected-error@second.h:* {{'TemplateParameters::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter 'B'}}
2490 // expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2491 #endif
2493 #if defined(FIRST)
2494 template <class A = double>
2495 struct S2 {};
2496 #elif defined(SECOND)
2497 template <class A = int>
2498 struct S2 {};
2499 #else
2500 using TemplateParameters::S2;
2501 // 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}}
2502 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2503 #endif
2505 #if defined(FIRST)
2506 template <class A = int>
2507 struct S3 {};
2508 #elif defined(SECOND)
2509 template <class A>
2510 struct S3 {};
2511 #else
2512 using TemplateParameters::S3;
2513 // 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}}
2514 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with default argument}}
2515 #endif
2517 #if defined(FIRST)
2518 template <int A>
2519 struct S4 {};
2520 #elif defined(SECOND)
2521 template <int A = 2>
2522 struct S4 {};
2523 #else
2524 using TemplateParameters::S4;
2525 // 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}}
2526 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with no default argument}}
2527 #endif
2529 #if defined(FIRST)
2530 template <int> class S5_first {};
2531 template <template<int> class A = S5_first>
2532 struct S5 {};
2533 #elif defined(SECOND)
2534 template <int> class S5_second {};
2535 template <template<int> class A = S5_second>
2536 struct S5 {};
2537 #else
2538 using TemplateParameters::S5;
2539 // 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}}
2540 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2541 #endif
2543 #if defined(FIRST)
2544 template <class A>
2545 struct S6 {};
2546 #elif defined(SECOND)
2547 template <class>
2548 struct S6 {};
2549 #else
2550 using TemplateParameters::S6;
2551 // expected-error@second.h:* {{'TemplateParameters::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found unnamed template parameter}}
2552 // expected-note@first.h:* {{but in 'FirstModule' found template parameter 'A'}}
2553 #endif
2555 #if defined(FIRST)
2556 template <int A = 7>
2557 struct S7 {};
2558 #elif defined(SECOND)
2559 template <int A = 8>
2560 struct S7 {};
2561 #else
2562 using TemplateParameters::S7;
2563 // expected-error@second.h:* {{'TemplateParameters::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}}
2564 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2565 #endif
2567 #if defined(FIRST)
2568 template <int* A = nullptr>
2569 struct S8 {};
2570 #elif defined(SECOND)
2571 inline int S8_default_arg = 0x12345;
2572 template <int* A = &S8_default_arg>
2573 struct S8 {};
2574 #else
2575 using TemplateParameters::S8;
2576 // expected-error@second.h:* {{'TemplateParameters::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found template parameter with default argument}}
2577 // expected-note@first.h:* {{but in 'FirstModule' found template parameter with different default argument}}
2578 #endif
2580 #if defined(FIRST)
2581 template <int A = 43>
2582 struct S9 {};
2583 #elif defined(SECOND)
2584 template <int A = 43>
2585 struct S9 {};
2586 #else
2587 using TemplateParameters::S9;
2588 #endif
2590 #if defined(FIRST)
2591 template <class A = double>
2592 struct S10 {};
2593 #elif defined(SECOND)
2594 template <class A = double>
2595 struct S10 {};
2596 #else
2597 using TemplateParameters::S10;
2598 #endif
2600 #if defined(FIRST)
2601 template <template<int> class A = S9>
2602 struct S11 {};
2603 #elif defined(SECOND)
2604 template <template<int> class A = S9>
2605 struct S11 {};
2606 #else
2607 using TemplateParameters::S11;
2608 #endif
2610 // FIXME: It looks like we didn't implement ODR check for template variables.
2611 // S12, S13 and S14 show this.
2612 #if defined(FIRST)
2613 template <int A = 43>
2614 int S12 {};
2615 #elif defined(SECOND)
2616 template <int A = 44>
2617 int S12 {};
2618 #else
2619 using TemplateParameters::S12;
2620 #endif
2622 #if defined(FIRST)
2623 template <class A = double>
2624 int S13 {};
2625 #elif defined(SECOND)
2626 template <class A = int>
2627 int S13 {};
2628 #else
2629 using TemplateParameters::S13;
2630 #endif
2632 #if defined(FIRST)
2633 template <class A>
2634 int S14 {};
2635 #elif defined(SECOND)
2636 template <class B>
2637 int S14 {};
2638 #else
2639 using TemplateParameters::S14;
2640 #endif
2642 #define DECLS
2644 #if defined(FIRST) || defined(SECOND)
2645 template <class> class DefaultArg;
2646 #endif
2648 #if defined(FIRST) || defined(SECOND)
2649 template <int, class, template <class> class,
2650 int A, class B, template <int> class C,
2651 int D = 1, class E = int, template <class F> class = DefaultArg>
2652 struct Valid1 {
2653 DECLS
2655 #else
2656 using TemplateParameters::Valid1;
2657 #endif
2659 #if defined(FIRST) || defined(SECOND)
2660 template <int, class, template <class> class,
2661 int A, class B, template <int> class C,
2662 int D = 1, class E = int, template <class F> class = DefaultArg>
2663 struct Invalid1 {
2664 DECLS
2665 ACCESS
2667 #else
2668 using TemplateParameters::Invalid1;
2669 // expected-error@second.h:* {{'TemplateParameters::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2670 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2671 #endif
2672 #undef DECLS
2673 } // namespace TemplateParameters
2675 namespace BaseClass {
2676 #if defined(FIRST)
2677 struct B1 {};
2678 struct S1 : B1 {};
2679 #elif defined(SECOND)
2680 struct S1 {};
2681 #else
2682 S1 s1;
2683 // expected-error@second.h:* {{'BaseClass::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 base classes}}
2684 // expected-note@first.h:* {{but in 'FirstModule' found 1 base class}}
2685 #endif
2687 #if defined(FIRST)
2688 struct S2 {};
2689 #elif defined(SECOND)
2690 struct B2 {};
2691 struct S2 : virtual B2 {};
2692 #else
2693 S2 s2;
2694 // expected-error@second.h:* {{'BaseClass::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 base class}}
2695 // expected-note@first.h:* {{but in 'FirstModule' found 0 base classes}}
2696 #endif
2698 #if defined(FIRST)
2699 struct B3a {};
2700 struct S3 : B3a {};
2701 #elif defined(SECOND)
2702 struct B3b {};
2703 struct S3 : virtual B3b {};
2704 #else
2705 S3 s3;
2706 // expected-error@second.h:* {{'BaseClass::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2707 // expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2708 #endif
2710 #if defined(FIRST)
2711 struct B4a {};
2712 struct S4 : B4a {};
2713 #elif defined(SECOND)
2714 struct B4b {};
2715 struct S4 : B4b {};
2716 #else
2717 S4 s4;
2718 // 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 'B4b'}}
2719 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class with different type 'B4a'}}
2720 #endif
2722 #if defined(FIRST)
2723 struct B5a {};
2724 struct S5 : virtual B5a {};
2725 #elif defined(SECOND)
2726 struct B5a {};
2727 struct S5 : B5a {};
2728 #else
2729 S5 s5;
2730 // expected-error@second.h:* {{'BaseClass::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found 0 virtual base classes}}
2731 // expected-note@first.h:* {{but in 'FirstModule' found 1 virtual base class}}
2732 #endif
2734 #if defined(FIRST)
2735 struct B6a {};
2736 struct S6 : B6a {};
2737 #elif defined(SECOND)
2738 struct B6a {};
2739 struct S6 : virtual B6a {};
2740 #else
2741 S6 s6;
2742 // expected-error@second.h:* {{'BaseClass::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1 virtual base class}}
2743 // expected-note@first.h:* {{but in 'FirstModule' found 0 virtual base classes}}
2744 #endif
2746 #if defined(FIRST)
2747 struct B7a {};
2748 struct S7 : protected B7a {};
2749 #elif defined(SECOND)
2750 struct B7a {};
2751 struct S7 : B7a {};
2752 #else
2753 S7 s7;
2754 // expected-error@second.h:* {{'BaseClass::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B7a' with no access specifier}}
2755 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B7a' with protected access specifier}}
2756 #endif
2758 #if defined(FIRST)
2759 struct B8a {};
2760 struct S8 : public B8a {};
2761 #elif defined(SECOND)
2762 struct B8a {};
2763 struct S8 : private B8a {};
2764 #else
2765 S8 s8;
2766 // expected-error@second.h:* {{'BaseClass::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B8a' with private access specifier}}
2767 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B8a' with public access specifier}}
2768 #endif
2770 #if defined(FIRST)
2771 struct B9a {};
2772 struct S9 : private B9a {};
2773 #elif defined(SECOND)
2774 struct B9a {};
2775 struct S9 : public B9a {};
2776 #else
2777 S9 s9;
2778 // expected-error@second.h:* {{'BaseClass::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B9a' with public access specifier}}
2779 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B9a' with private access specifier}}
2780 #endif
2782 #if defined(FIRST)
2783 struct B10a {};
2784 struct S10 : B10a {};
2785 #elif defined(SECOND)
2786 struct B10a {};
2787 struct S10 : protected B10a {};
2788 #else
2789 S10 s10;
2790 // expected-error@second.h:* {{'BaseClass::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found 1st base class 'B10a' with protected access specifier}}
2791 // expected-note@first.h:* {{but in 'FirstModule' found 1st base class 'B10a' with no access specifier}}
2792 #endif
2794 #define DECLS
2796 #if defined(FIRST) || defined(SECOND)
2797 struct Base1 {};
2798 struct Base2 {};
2799 struct Base3 {};
2800 struct Base4 {};
2801 struct Base5 {};
2802 #endif
2804 #if defined(FIRST) || defined(SECOND)
2805 struct Valid1 :
2806 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2808 DECLS
2810 #else
2811 Valid1 v1;
2812 #endif
2814 #if defined(FIRST) || defined(SECOND)
2815 struct Invalid1 :
2816 Base1, virtual Base2, protected Base3, public Base4, private Base5 {
2818 DECLS
2819 ACCESS
2821 #else
2822 Invalid1 i1;
2823 // expected-error@second.h:* {{'BaseClass::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2824 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2825 #endif
2826 #undef DECLS
2827 } // namespace BaseClass
2829 namespace PointersAndReferences {
2830 #if defined(FIRST) || defined(SECOND)
2831 template<typename> struct Wrapper{};
2832 #endif
2834 #if defined(FIRST)
2835 struct S1 {
2836 Wrapper<int*> x;
2838 #elif defined(SECOND)
2839 struct S1 {
2840 Wrapper<float*> x;
2842 #else
2843 S1 s1;
2844 // expected-error@first.h:* {{PointersAndReferences::S1::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S1' in module 'SecondModule'}}
2845 // expected-note@second.h:* {{declaration of 'x' does not match}}
2846 #endif
2848 #if defined(FIRST)
2849 struct S2 {
2850 Wrapper<int &&> x;
2852 #elif defined(SECOND)
2853 struct S2 {
2854 Wrapper<float &&> x;
2856 #else
2857 S2 s2;
2858 // expected-error@first.h:* {{PointersAndReferences::S2::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S2' in module 'SecondModule'}}
2859 // expected-note@second.h:* {{declaration of 'x' does not match}}
2860 #endif
2862 #if defined(FIRST)
2863 struct S3 {
2864 Wrapper<int *> x;
2866 #elif defined(SECOND)
2867 struct S3 {
2868 Wrapper<float *> x;
2870 #else
2871 S3 s3;
2872 // expected-error@first.h:* {{PointersAndReferences::S3::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S3' in module 'SecondModule'}}
2873 // expected-note@second.h:* {{declaration of 'x' does not match}}
2874 #endif
2876 #if defined(FIRST)
2877 struct S4 {
2878 Wrapper<int &> x;
2880 #elif defined(SECOND)
2881 struct S4 {
2882 Wrapper<float &> x;
2884 #else
2885 S4 s4;
2886 // expected-error@first.h:* {{PointersAndReferences::S4::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S4' in module 'SecondModule'}}
2887 // expected-note@second.h:* {{declaration of 'x' does not match}}
2888 #endif
2890 #if defined(FIRST)
2891 struct S5 {
2892 Wrapper<S5 *> x;
2894 #elif defined(SECOND)
2895 struct S5 {
2896 Wrapper<const S5 *> x;
2898 #else
2899 S5 s5;
2900 // expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 'SecondModule' is not present in definition of 'PointersAndReferences::S5' in module 'FirstModule'}}
2901 // expected-note@first.h:* {{declaration of 'x' does not match}}
2902 #endif
2904 #if defined(FIRST)
2905 struct S6 {
2906 Wrapper<int &> x;
2908 #elif defined(SECOND)
2909 struct S6 {
2910 Wrapper<const int &> x;
2912 #else
2913 S6 s6;
2914 // expected-error@first.h:* {{PointersAndReferences::S6::x' from module 'FirstModule' is not present in definition of 'PointersAndReferences::S6' in module 'SecondModule'}}
2915 // expected-note@second.h:* {{declaration of 'x' does not match}}
2916 #endif
2918 #define DECLS \
2919 Wrapper<int *> x1; \
2920 Wrapper<float *> x2; \
2921 Wrapper<const float *> x3; \
2922 Wrapper<int &> x4; \
2923 Wrapper<int &&> x5; \
2924 Wrapper<const int &> x6; \
2925 Wrapper<S1 *> x7; \
2926 Wrapper<S1 &> x8; \
2927 Wrapper<S1 &&> x9;
2929 #if defined(FIRST) || defined(SECOND)
2930 struct Valid1 {
2931 DECLS
2933 #else
2934 Valid1 v1;
2935 #endif
2937 #if defined(FIRST) || defined(SECOND)
2938 struct Invalid1 {
2939 DECLS
2940 ACCESS
2942 #else
2943 Invalid1 i1;
2944 // expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
2945 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
2946 #endif
2947 #undef DECLS
2948 } // namespace PointersAndReferences
2950 namespace FunctionTemplate {
2951 #if defined(FIRST)
2952 struct S1 {
2953 template <int, int> void foo();
2955 #elif defined(SECOND)
2956 struct S1 {
2957 template <int> void foo();
2959 #else
2960 S1 s1;
2961 // expected-error@first.h:* {{'FunctionTemplate::S1::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S1' in module 'SecondModule'}}
2962 // expected-note@second.h:* {{declaration of 'foo' does not match}}
2963 #endif
2965 #if defined(FIRST)
2966 struct S2 {
2967 template <char> void foo();
2969 #elif defined(SECOND)
2970 struct S2 {
2971 template <int> void foo();
2973 #else
2974 S2 s2;
2975 // expected-error@first.h:* {{'FunctionTemplate::S2::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S2' in module 'SecondModule'}}
2976 // expected-note@second.h:* {{declaration of 'foo' does not match}}
2977 #endif
2979 #if defined(FIRST)
2980 struct S3 {
2981 template <int x> void foo();
2983 #elif defined(SECOND)
2984 struct S3 {
2985 template <int y> void foo();
2987 #else
2988 S3 s3;
2989 // 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'}}
2990 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
2991 #endif
2993 #if defined(FIRST)
2994 struct S4 {
2995 template <int x> void foo();
2997 #elif defined(SECOND)
2998 struct S4 {
2999 template <int x> void bar();
3001 #else
3002 S4 s4;
3003 // expected-error@first.h:* {{'FunctionTemplate::S4::foo' from module 'FirstModule' is not present in definition of 'FunctionTemplate::S4' in module 'SecondModule'}}
3004 // expected-note@second.h:* {{definition has no member 'foo'}}
3005 #endif
3007 #if defined(FIRST)
3008 struct S5 {
3009 template <int x> void foo();
3011 #elif defined(SECOND)
3012 struct S5 {
3013 public:
3014 template <int x> void foo();
3016 #else
3017 S5 s5;
3018 // expected-error@second.h:* {{'FunctionTemplate::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3019 // expected-note@first.h:* {{but in 'FirstModule' found function template}}
3020 #endif
3022 #if defined(FIRST)
3023 struct S6 {
3024 template <typename x = int> void foo();
3026 #elif defined(SECOND)
3027 struct S6 {
3028 template <typename x> void foo();
3030 #else
3031 S6 s6;
3032 // 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}}
3033 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
3034 #endif
3036 #if defined(FIRST)
3037 struct S7 {
3038 template <typename x = void> void foo();
3040 #elif defined(SECOND)
3041 struct S7 {
3042 template <typename x = int> void foo();
3044 #else
3045 S7 s7;
3046 // 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'}}
3047 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'void'}}
3048 #endif
3050 #if defined(FIRST)
3051 template <int>
3052 struct U8 {};
3053 struct S8 {
3054 template <template<int> class x = U8> void foo();
3056 #elif defined(SECOND)
3057 template <int>
3058 struct T8 {};
3059 struct S8{
3060 template <template<int> class x = T8> void foo();
3062 #else
3063 S8 s8;
3064 // 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'}}
3065 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'U8'}}
3066 #endif
3068 #if defined(FIRST)
3069 template <int>
3070 struct U9 {};
3071 struct S9 { S9();
3072 template <template<int> class x = U9> void foo();
3074 #elif defined(SECOND)
3075 struct S9 { S9();
3076 template <template<int> class x> void foo();
3078 #else
3079 S9 s9;
3080 // 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}}
3081 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
3082 #endif
3084 #if defined(FIRST)
3085 struct S10 {
3086 template <template<int> class x> void foo();
3087 template <template<typename> class x> void foo();
3089 #elif defined(SECOND)
3090 struct S10 {
3091 template <template<typename> class x> void foo();
3092 template <template<int> class x> void foo();
3094 #else
3095 S10 s10;
3096 // 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}}
3097 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
3098 #endif
3100 #if defined(FIRST)
3101 struct S11 {
3102 template <template<int> class x> void foo();
3104 #elif defined(SECOND)
3105 struct S11 {
3106 template <template<int> class> void foo();
3108 #else
3109 S11 s11;
3110 // 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}}
3111 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter named 'x'}}
3112 #endif
3114 #if defined(FIRST)
3115 struct S12 {
3116 template <class> void foo();
3117 template <class, class> void foo();
3119 #elif defined(SECOND)
3120 struct S12 {
3121 template <class, class> void foo();
3122 template <class> void foo();
3124 #else
3125 S12 s12;
3126 // 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}}
3127 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1 template parameter}}
3128 #endif
3130 #if defined(FIRST)
3131 struct S13 {
3132 template <class = int> void foo();
3134 #elif defined(SECOND)
3135 struct S13 {
3136 template <class = void> void foo();
3138 #else
3139 S13 s13;
3140 // 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'}}
3141 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 'int'}}
3142 #endif
3144 #if defined(FIRST)
3145 struct S14 {
3146 template <class = void> void foo();
3148 #elif defined(SECOND)
3149 struct S14 {
3150 template <class> void foo();
3152 #else
3153 S14 s14;
3154 // 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}}
3155 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument}}
3156 #endif
3158 #if defined(FIRST)
3159 struct S15 {
3160 template <class> void foo();
3162 #elif defined(SECOND)
3163 struct S15 {
3164 template <class = void> void foo();
3166 #else
3167 S15 s15;
3168 // 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}}
3169 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
3170 #endif
3172 #if defined(FIRST)
3173 struct S16 {
3174 template <short> void foo();
3176 #elif defined(SECOND)
3177 struct S16 {
3178 template <short = 1> void foo();
3180 #else
3181 S16 s16;
3182 // 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}}
3183 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with no default argument}}
3184 #endif
3186 #if defined(FIRST)
3187 struct S17 {
3188 template <short = 2> void foo();
3190 #elif defined(SECOND)
3191 struct S17 {
3192 template <short = 1 + 1> void foo();
3194 #else
3195 S17 s17;
3196 // 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}}
3197 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with default argument 2}}
3198 #endif
3200 #if defined(FIRST)
3201 struct S18 {
3202 template <short> void foo();
3203 template <int> void foo();
3205 #elif defined(SECOND)
3206 struct S18 {
3207 template <int> void foo();
3208 template <short> void foo();
3210 #else
3211 S18 s18;
3212 // 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}}
3213 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter with different type}}
3214 #endif
3216 #if defined(FIRST)
3217 struct S19 {
3218 template <short> void foo();
3219 template <short...> void foo();
3221 #elif defined(SECOND)
3222 struct S19 {
3223 template <short...> void foo();
3224 template <short> void foo();
3226 #else
3227 S19 s19;
3228 // 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}}
3229 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
3230 #endif
3232 #if defined(FIRST)
3233 struct S20 {
3234 template <class> void foo();
3235 template <class...> void foo();
3237 #elif defined(SECOND)
3238 struct S20 {
3239 template <class...> void foo();
3240 template <class> void foo();
3242 #else
3243 S20 s20;
3244 // 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}}
3245 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter not being a template parameter pack}}
3246 #endif
3248 #if defined(FIRST)
3249 struct S21 {
3250 template <template<class> class...> void foo();
3251 template <template<class> class> void foo();
3253 #elif defined(SECOND)
3254 struct S21 {
3255 template <template<class> class> void foo();
3256 template <template<class> class...> void foo();
3258 #else
3259 S21 s21;
3260 // 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}}
3261 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template parameter being a template parameter pack}}
3262 #endif
3264 #if defined(FIRST)
3265 struct S22 {
3266 template <template<class> class> void foo();
3267 template <class> void foo();
3268 template <int> void foo();
3270 #elif defined(SECOND)
3271 struct S22 {
3272 template <class> void foo();
3273 template <int> void foo();
3274 template <template<class> class> void foo();
3276 #else
3277 S22 s22;
3278 // 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}}
3279 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a template template parameter}}
3280 #endif
3282 #if defined(FIRST)
3283 struct S23 {
3284 template <class> void foo();
3285 template <int> void foo();
3286 template <template<class> class> void foo();
3288 #elif defined(SECOND)
3289 struct S23 {
3290 template <int> void foo();
3291 template <template<class> class> void foo();
3292 template <class> void foo();
3294 #else
3295 S23 s23;
3296 // 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}}
3297 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a type template parameter}}
3298 #endif
3300 #if defined(FIRST)
3301 struct S24 {
3302 template <int> void foo();
3303 template <template<class> class> void foo();
3304 template <class> void foo();
3306 #elif defined(SECOND)
3307 struct S24 {
3308 template <template<class> class> void foo();
3309 template <class> void foo();
3310 template <int> void foo();
3312 #else
3313 S24 s24;
3314 // 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}}
3315 // expected-note@first.h:* {{but in 'FirstModule' found function template 'foo' with 1st template paramter being a non-type template parameter}}
3316 #endif
3318 #if defined(FIRST)
3319 struct S25 {
3320 template <int> void foo();
3322 #elif defined(SECOND)
3323 struct S25 {
3324 public:
3325 template <int> void foo();
3327 #else
3328 S25 s25;
3329 // expected-error@second.h:* {{'FunctionTemplate::S25' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
3330 // expected-note@first.h:* {{but in 'FirstModule' found function template}}
3331 #endif
3333 #define DECLS \
3334 template <int> \
3335 void nontype1(); \
3336 template <int x> \
3337 void nontype2(); \
3338 template <int, int> \
3339 void nontype3(); \
3340 template <int x = 5> \
3341 void nontype4(); \
3342 template <int... x> \
3343 void nontype5(); \
3345 template <class> \
3346 void type1(); \
3347 template <class x> \
3348 void type2(); \
3349 template <class, class> \
3350 void type3(); \
3351 template <class x = int> \
3352 void type4(); \
3353 template <class... x> \
3354 void type5(); \
3356 template <template <int> class> \
3357 void template1(); \
3358 template <template <int> class x> \
3359 void template2(); \
3360 template <template <int> class, template <int> class> \
3361 void template3(); \
3362 template <template <int> class x = U> \
3363 void template4(); \
3364 template <template <int> class... x> \
3365 void template5();
3367 #if defined(FIRST) || defined(SECOND)
3368 template<int>
3369 struct U {};
3370 struct Valid1 {
3371 DECLS
3373 #else
3374 Valid1 v1;
3375 #endif
3377 #if defined(FIRST) || defined(SECOND)
3378 struct Invalid1 {
3379 DECLS
3380 ACCESS
3382 #else
3383 Invalid1 i1;
3384 // expected-error@second.h:* {{'FunctionTemplate::Invalid1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
3385 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
3386 #endif
3387 #undef DECLS
3390 namespace Enums {
3391 #if defined(FIRST)
3392 enum E1 { x11 };
3393 #elif defined(SECOND)
3394 enum E1 {};
3395 #else
3396 E1 e1;
3397 // expected-error@first.h:* {{'Enums::x11' from module 'FirstModule' is not present in definition of 'Enums::E1' in module 'SecondModule'}}
3398 // expected-note@second.h:* {{definition has no member 'x11'}}
3399 #endif
3401 #if defined(FIRST)
3402 enum E2 {};
3403 #elif defined(SECOND)
3404 enum E2 { x21 };
3405 #else
3406 E2 e2;
3407 // expected-error@second.h:* {{'Enums::E2' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 1 element}}
3408 // expected-note@first.h:* {{but in 'FirstModule' found enum with 0 elements}}
3409 #endif
3411 #if defined(FIRST)
3412 enum E3 { x31 };
3413 #elif defined(SECOND)
3414 enum E3 { x32 };
3415 #else
3416 E3 e3;
3417 // expected-error@first.h:* {{'Enums::x31' from module 'FirstModule' is not present in definition of 'Enums::E3' in module 'SecondModule'}}
3418 // expected-note@second.h:* {{definition has no member 'x31'}}
3419 #endif
3421 #if defined(FIRST)
3422 enum E4 { x41 };
3423 #elif defined(SECOND)
3424 enum E4 { x41, x42 };
3425 #else
3426 E4 e4;
3427 // expected-error@second.h:* {{'Enums::E4' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with 2 elements}}
3428 // expected-note@first.h:* {{but in 'FirstModule' found enum with 1 element}}
3429 #endif
3431 #if defined(FIRST)
3432 enum E5 { x51, x52 };
3433 #elif defined(SECOND)
3434 enum E5 { x51 };
3435 #else
3436 E5 e5;
3437 // expected-error@first.h:* {{'Enums::x52' from module 'FirstModule' is not present in definition of 'Enums::E5' in module 'SecondModule'}}
3438 // expected-note@second.h:* {{definition has no member 'x52'}}
3439 #endif
3441 #if defined(FIRST)
3442 enum E6 { x61, x62 };
3443 #elif defined(SECOND)
3444 enum E6 { x62, x61 };
3445 #else
3446 E6 e6;
3447 // expected-error@second.h:* {{'Enums::E6' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element has name 'x62'}}
3448 // expected-note@first.h:* {{but in 'FirstModule' found 1st element has name 'x61'}}
3449 #endif
3451 #if defined(FIRST)
3452 enum E7 { x71 = 0 };
3453 #elif defined(SECOND)
3454 enum E7 { x71 };
3455 #else
3456 E7 e7;
3457 // expected-error@second.h:* {{'Enums::E7' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st element 'x71' has an initializer}}
3458 // expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x71' does not have an initializer}}
3459 #endif
3461 #if defined(FIRST)
3462 enum E8 { x81 };
3463 #elif defined(SECOND)
3464 enum E8 { x81 = 0 };
3465 #else
3466 E8 e8;
3467 // 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 initializer}}
3468 // expected-note@first.h:* {{but in 'FirstModule' found 1st element 'x81' has an initializer}}
3469 #endif
3471 #if defined(FIRST)
3472 enum E9 { x91 = 0, x92 = 1 };
3473 #elif defined(SECOND)
3474 enum E9 { x91 = 0, x92 = 2 - 1 };
3475 #else
3476 E9 e9;
3477 // 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}}
3478 // expected-note@first.h:* {{but in 'FirstModule' found 2nd element 'x92' has different initializer}}
3479 #endif
3481 #if defined(FIRST)
3482 enum class E10 : int {};
3483 #elif defined(SECOND)
3484 enum class E10 {};
3485 #else
3486 E10 e10;
3487 // expected-error@second.h:* {{'Enums::E10' has different definitions in different modules; definition in module 'SecondModule' first difference is enum without specified type}}
3488 // expected-note@first.h:* {{but in 'FirstModule' found enum with specified type}}
3489 #endif
3491 #if defined(FIRST)
3492 enum E11 {};
3493 #elif defined(SECOND)
3494 enum E11 : int {};
3495 #else
3496 E11 e11;
3497 // expected-error@second.h:* {{'Enums::E11' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type}}
3498 // expected-note@first.h:* {{but in 'FirstModule' found enum without specified type}}
3499 #endif
3501 #if defined(FIRST)
3502 enum struct E12 : long {};
3503 #elif defined(SECOND)
3504 enum struct E12 : int {};
3505 #else
3506 E12 e12;
3507 // expected-error@second.h:* {{'Enums::E12' has different definitions in different modules; definition in module 'SecondModule' first difference is enum with specified type 'int'}}
3508 // expected-note@first.h:* {{but in 'FirstModule' found enum with specified type 'long'}}
3509 #endif
3511 #if defined(FIRST)
3512 enum struct E13 {};
3513 #elif defined(SECOND)
3514 enum E13 {};
3515 #else
3516 E13 e13;
3517 // expected-error@second.h:* {{'Enums::E13' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is not scoped}}
3518 // expected-note@first.h:* {{but in 'FirstModule' found enum that is scoped}}
3519 #endif
3521 #if defined(FIRST)
3522 enum E14 {};
3523 #elif defined(SECOND)
3524 enum struct E14 {};
3525 #else
3526 E14 e14;
3527 // expected-error@second.h:* {{'Enums::E14' has different definitions in different modules; definition in module 'SecondModule' first difference is enum that is scoped}}
3528 // expected-note@first.h:* {{but in 'FirstModule' found enum that is not scoped}}
3529 #endif
3531 #if defined(FIRST)
3532 enum class E15 {};
3533 #elif defined(SECOND)
3534 enum struct E15 {};
3535 #else
3536 E15 e15;
3537 // expected-error@second.h:* {{'Enums::E15' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword struct}}
3538 // expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword class}}
3539 #endif
3541 #if defined(FIRST)
3542 enum struct E16 {};
3543 #elif defined(SECOND)
3544 enum class E16 {};
3545 #else
3546 E16 e16;
3547 // expected-error@second.h:* {{'Enums::E16' has different definitions in different modules; definition in module 'SecondModule' first difference is enum scoped with keyword class}}
3548 // expected-note@first.h:* {{but in 'FirstModule' found enum scoped with keyword struct}}
3549 #endif
3551 #if defined(FIRST)
3552 enum Valid { v1 = (struct S*)0 == (struct S*)0 };
3553 #elif defined(SECOND)
3554 struct S {};
3555 enum Valid { v1 = (struct S*)0 == (struct S*)0 };
3556 #else
3557 Valid V;
3558 #endif
3559 } // namespace Enums
3561 namespace Types {
3562 namespace Complex {
3563 #if defined(FIRST)
3564 void invalid() {
3565 _Complex float x;
3567 void valid() {
3568 _Complex float x;
3570 #elif defined(SECOND)
3571 void invalid() {
3572 _Complex double x;
3574 void valid() {
3575 _Complex float x;
3577 #else
3578 auto function1 = invalid;
3579 // expected-error@second.h:* {{'Types::Complex::invalid' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3580 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3581 auto function2 = valid;
3582 #endif
3583 } // namespace Complex
3585 namespace Decltype {
3586 #if defined(FIRST)
3587 void invalid1() {
3588 decltype(1 + 1) x;
3590 int global;
3591 void invalid2() {
3592 decltype(global) x;
3594 void valid() {
3595 decltype(1.5) x;
3596 decltype(x) y;
3598 #elif defined(SECOND)
3599 void invalid1() {
3600 decltype(2) x;
3602 float global;
3603 void invalid2() {
3604 decltype(global) x;
3606 void valid() {
3607 decltype(1.5) x;
3608 decltype(x) y;
3610 #else
3611 auto function1 = invalid1;
3612 // expected-error@second.h:* {{'Types::Decltype::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3613 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3614 auto function2 = invalid2;
3615 // FIXME: We should reject the merge of `invalid2` and diagnose about the
3616 // inconsistent definition of `global`.
3617 auto function3 = valid;
3618 #endif
3619 } // namespace Decltype
3621 namespace Auto {
3622 #if defined(FIRST)
3623 void invalid1() {
3624 decltype(auto) x = 1;
3626 void invalid2() {
3627 auto x = 1;
3629 void invalid3() {
3630 __auto_type x = 1;
3632 void valid() {
3633 decltype(auto) x = 1;
3634 auto y = 1;
3635 __auto_type z = 1;
3637 #elif defined(SECOND)
3638 void invalid1() {
3639 auto x = 1;
3641 void invalid2() {
3642 __auto_type x = 1;
3644 void invalid3() {
3645 decltype(auto) x = 1;
3647 void valid() {
3648 decltype(auto) x = 1;
3649 auto y = 1;
3650 __auto_type z = 1;
3652 #else
3653 auto function1 = invalid1;
3654 // expected-error@second.h:* {{'Types::Auto::invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3655 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3656 auto function2 = invalid3;
3657 // expected-error@second.h:* {{'Types::Auto::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3658 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3659 auto function3 = invalid2;
3660 // expected-error@second.h:* {{'Types::Auto::invalid3' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3661 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3662 auto function4 = valid;
3663 #endif
3664 } // namespace Auto
3666 namespace DeducedTemplateSpecialization {
3667 #if defined(FIRST)
3668 template<typename T> struct A {};
3669 A() -> A<int>;
3670 template<typename T> struct B {};
3671 B() -> B<int>;
3673 void invalid1() {
3674 A a{};
3676 void invalid2() {
3677 A a{};
3679 void valid() {
3680 B b{};
3682 #elif defined(SECOND)
3683 template<typename T> struct A {};
3684 A() -> A<float>;
3685 template<typename T> struct B {};
3686 B() -> B<int>;
3688 void invalid1() {
3689 A a{};
3691 void invalid2() {
3692 B a{};
3694 void valid() {
3695 B b{};
3697 #else
3698 auto function1 = invalid1;
3699 // FIXME: We should reject the merge of `invalid1` due to the inconsistent definition.
3700 auto function2 = invalid2;
3701 // expected-error@second.h:* {{'Types::DeducedTemplateSpecialization::invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3702 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3703 auto function3 = valid;
3704 #endif
3705 } // namespace DeducedTemplateSpecialization
3707 namespace DependentAddressSpace {
3708 #if defined(FIRST)
3709 template <int A1, int A2>
3710 void invalid1() {
3711 using type = int __attribute__((address_space(A1)));
3713 template <int A1>
3714 void invalid2() {
3715 using type = float __attribute__((address_space(A1)));
3717 template <int A1, int A2>
3718 void valid() {
3719 using type1 = float __attribute__((address_space(A1)));
3720 using type2 = int __attribute__((address_space(A2)));
3721 using type3 = int __attribute__((address_space(A1 + A2)));
3723 #elif defined(SECOND)
3724 template <int A1, int A2>
3725 void invalid1() {
3726 using type = int __attribute__((address_space(A2)));
3728 template <int A1>
3729 void invalid2() {
3730 using type = int __attribute__((address_space(A1)));
3732 template <int A1, int A2>
3733 void valid() {
3734 using type1 = float __attribute__((address_space(A1)));
3735 using type2 = int __attribute__((address_space(A2)));
3736 using type3 = int __attribute__((address_space(A1 + A2)));
3738 #else
3739 template <int A, int B>
3740 class S {
3741 static auto function1 = invalid1<A, B>;
3742 // expected-error@first.h:* {{'Types::DependentAddressSpace::invalid1' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3743 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3744 static auto function2 = invalid2<B>;
3745 // expected-error@first.h:* {{'Types::DependentAddressSpace::invalid2' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3746 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3747 static auto function3 = valid<A, B>;
3749 #endif
3750 } // namespace DependentAddressSpace
3752 namespace DependentSizedExtVector {
3753 #if defined(FIRST)
3754 template<int Size>
3755 void invalid1() {
3756 typedef int __attribute__((ext_vector_type(Size))) type;
3758 template<int Size>
3759 void invalid2() {
3760 typedef int __attribute__((ext_vector_type(Size + 0))) type;
3762 template<int Size>
3763 void valid() {
3764 typedef int __attribute__((ext_vector_type(Size))) type;
3766 #elif defined(SECOND)
3767 template<int Size>
3768 void invalid1() {
3769 typedef float __attribute__((ext_vector_type(Size))) type;
3771 template<int Size>
3772 void invalid2() {
3773 typedef int __attribute__((ext_vector_type(Size + 1))) type;
3775 template<int Size>
3776 void valid() {
3777 typedef int __attribute__((ext_vector_type(Size))) type;
3779 #else
3780 template <int Num>
3781 class S {
3782 static auto Function1 = invalid1<Num>;
3783 // expected-error@first.h:* {{'Types::DependentSizedExtVector::invalid1' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3784 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3785 static auto Function2 = invalid2<Num>;
3786 // expected-error@first.h:* {{'Types::DependentSizedExtVector::invalid2' has different definitions in different modules; definition in module 'FirstModule' first difference is function body}}
3787 // expected-note@second.h:* {{but in 'SecondModule' found a different body}}
3788 static auto Function3 = valid<Num>;
3790 #endif
3791 } // namespace DependentSizedExtVector
3793 namespace InjectedClassName {
3794 #if defined(FIRST)
3795 struct Invalid {
3796 template <int>
3797 struct L2 {
3798 template <int>
3799 struct L3 {
3800 L3 *x;
3804 struct Valid {
3805 template <int>
3806 struct L2 {
3807 template <int>
3808 struct L3 {
3809 L2 *x;
3810 L3 *y;
3814 #elif defined(SECOND)
3815 struct Invalid {
3816 template <int>
3817 struct L2 {
3818 template <int>
3819 struct L3 {
3820 L2 *x;
3824 struct Valid {
3825 template <int>
3826 struct L2 {
3827 template <int>
3828 struct L3 {
3829 L2 *x;
3830 L3 *y;
3834 #else
3835 Invalid::L2<1>::L3<1> invalid;
3836 // expected-error@second.h:* {{'Types::InjectedClassName::Invalid::L2::L3::x' from module 'SecondModule' is not present in definition of 'L3<>' in module 'FirstModule'}}
3837 // expected-note@first.h:* {{declaration of 'x' does not match}}
3838 Valid::L2<1>::L3<1> valid;
3839 #endif
3840 } // namespace InjectedClassName
3842 namespace MemberPointer {
3843 #if defined(FIRST)
3844 struct A {};
3845 struct B {};
3847 void Invalid1() {
3848 int A::*x;
3850 void Invalid2() {
3851 int A::*x;
3853 void Invalid3() {
3854 int (A::*x)(int);
3856 void Valid() {
3857 int A::*x;
3858 float A::*y;
3859 bool B::*z;
3860 void (A::*fun1)();
3861 int (A::*fun2)();
3862 void (B::*fun3)(int);
3863 void (B::*fun4)(bool*, int);
3865 #elif defined(SECOND)
3866 struct A {};
3867 struct B {};
3869 void Invalid1() {
3870 float A::*x;
3872 void Invalid2() {
3873 int B::*x;
3875 void Invalid3() {
3876 int (A::*x)(int, int);
3878 void Valid() {
3879 int A::*x;
3880 float A::*y;
3881 bool B::*z;
3882 void (A::*fun1)();
3883 int (A::*fun2)();
3884 void (B::*fun3)(int);
3885 void (B::*fun4)(bool*, int);
3887 #else
3888 auto function1 = Invalid1;
3889 // expected-error@second.h:* {{'Types::MemberPointer::Invalid1' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3890 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3891 auto function2 = Invalid2;
3892 // expected-error@second.h:* {{'Types::MemberPointer::Invalid2' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3893 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3894 auto function3 = Invalid3;
3895 // expected-error@second.h:* {{'Types::MemberPointer::Invalid3' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3896 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3897 auto function4 = Valid;
3898 #endif
3900 } // namespace MemberPointer
3902 namespace PackExpansion {
3903 #if defined(FIRST)
3904 struct Invalid {
3905 template <class... A>
3906 struct L2 {
3907 template <class... B>
3908 struct L3 {
3909 void run(A...);
3910 void run(B...);
3914 struct Valid {
3915 template <class... A>
3916 struct L2 {
3917 template <class... B>
3918 struct L3 {
3919 void run(A...);
3920 void run(B...);
3924 #elif defined(SECOND)
3925 struct Invalid {
3926 template <class... A>
3927 struct L2 {
3928 template <class... B>
3929 struct L3 {
3930 void run(B...);
3931 void run(A...);
3935 struct Valid {
3936 template <class... A>
3937 struct L2 {
3938 template <class... B>
3939 struct L3 {
3940 void run(A...);
3941 void run(B...);
3945 #else
3946 Invalid::L2<int>::L3<short, bool> invalid;
3947 // 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...'}}
3948 // expected-note@second.h:* {{but in 'SecondModule' found method 'run' with 1st parameter of type 'B...'}}
3949 Valid::L2<int>::L3<short, bool> valid;
3950 #endif
3952 } // namespace PackExpansion
3954 namespace Paren {
3955 #if defined(FIRST)
3956 void invalid() {
3957 int (*x);
3959 void valid() {
3960 int (*x);
3962 #elif defined(SECOND)
3963 void invalid() {
3964 float (*x);
3966 void valid() {
3967 int (*x);
3969 #else
3970 auto function1 = invalid;
3971 // expected-error@second.h:* {{'Types::Paren::invalid' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
3972 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
3973 auto function2 = valid;
3974 #endif
3975 } // namespace Paren
3977 namespace SubstTemplateTypeParm {
3978 #if defined(FIRST)
3979 template <class> struct wrapper {};
3980 template <class, class, class> struct triple {};
3981 struct Valid {
3982 template <class T,
3983 template <class _T, class _U, class = wrapper<_T>> class A = triple>
3984 struct L2 {
3985 A<T, T> x;
3988 #elif defined(SECOND)
3989 template <class> struct wrapper {};
3990 template <class, class, class> struct triple {};
3991 struct Valid {
3992 template <class T,
3993 template <class _T, class _U, class = wrapper<_T>> class A = triple>
3994 struct L2 {
3995 A<T, T> x;
3998 #else
3999 template <class T,
4000 template <class _T, class _U, class = wrapper<_T>> class A = triple>
4001 using V = Valid::L2<T, A>;
4002 #endif
4003 } // namespace SubstTemplateTypeParm
4005 namespace SubstTemplateTypeParmPack {
4006 } // namespace SubstTemplateTypeParmPack
4008 namespace UnaryTransform {
4009 #if defined(FIRST)
4010 enum class E1a : unsigned {};
4011 struct Invalid1 {
4012 __underlying_type(E1a) x;
4014 enum E2a : unsigned {};
4015 struct Invalid2 {
4016 __underlying_type(E2a) x;
4018 enum E3a {};
4019 struct Invalid3 {
4020 __underlying_type(E3a) x;
4022 enum E4a {};
4023 struct Invalid4 {
4024 __underlying_type(E4a) x;
4026 enum E1 {};
4027 struct Valid1 {
4028 __underlying_type(E1) x;
4030 enum E2 : unsigned {};
4031 struct Valid2 {
4032 __underlying_type(E2) x;
4034 enum class E3 {};
4035 struct Valid3 {
4036 __underlying_type(E3) x;
4038 #elif defined(SECOND)
4039 enum class E1b : signed {};
4040 struct Invalid1 {
4041 __underlying_type(E1b) x;
4043 enum class E2b : unsigned {};
4044 struct Invalid2 {
4045 __underlying_type(E2b) x;
4047 enum E3b : int {};
4048 struct Invalid3 {
4049 __underlying_type(E3b) x;
4051 enum E4b {};
4052 struct Invalid4 {
4053 __underlying_type(E4b) x;
4055 #else
4056 Invalid1 i1;
4057 // expected-error@first.h:* {{'Types::UnaryTransform::Invalid1::x' from module 'FirstModule' is not present in definition of 'Types::UnaryTransform::Invalid1' in module 'SecondModule'}}
4058 // expected-note@second.h:* {{declaration of 'x' does not match}}
4059 Invalid2 i2;
4060 // 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(E2b)' (aka 'unsigned int')}}
4061 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type '__underlying_type(E2a)' (aka 'unsigned int')}}
4062 Invalid3 i3;
4063 // expected-error@first.h:* {{'Types::UnaryTransform::Invalid3::x' from module 'FirstModule' is not present in definition of 'Types::UnaryTransform::Invalid3' in module 'SecondModule'}}
4064 // expected-note@second.h:* {{declaration of 'x' does not match}}
4065 Invalid4 i4;
4066 // 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(E4b)' (aka 'unsigned int')}}
4067 // expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type '__underlying_type(E4a)' (aka 'unsigned int')}}
4068 Valid1 v1;
4069 Valid2 v2;
4070 Valid3 v3;
4071 #endif
4072 } // namespace UnaryTransform
4074 namespace UnresolvedUsing {
4075 #if defined(FIRST)
4076 template <class T> struct wrapper {};
4077 template <class T>
4078 struct Invalid {
4079 using typename wrapper<T>::T1;
4080 using typename wrapper<T>::T2;
4081 T1 x;
4083 template <class T>
4084 struct Valid {
4085 using typename wrapper<T>::T1;
4086 using typename wrapper<T>::T2;
4087 T1 x;
4088 T2 y;
4090 #elif defined(SECOND)
4091 template <class T> struct wrapper {};
4092 template <class T>
4093 struct Invalid {
4094 using typename wrapper<T>::T1;
4095 using typename wrapper<T>::T2;
4096 T2 x;
4098 template <class T>
4099 struct Valid {
4100 using typename wrapper<T>::T1;
4101 using typename wrapper<T>::T2;
4102 T1 x;
4103 T2 y;
4105 #else
4106 template <class T> using I = Invalid<T>;
4107 // expected-error@first.h:* {{'Types::UnresolvedUsing::Invalid::x' from module 'FirstModule' is not present in definition of 'Invalid<T>' in module 'SecondModule'}}
4108 // expected-note@second.h:* {{declaration of 'x' does not match}}
4110 template <class T> using V = Valid<T>;
4111 #endif
4113 } // namespace UnresolvedUsing
4115 // Vector
4116 // void invalid1() {
4117 // __attribute((vector_size(8))) int *x1;
4120 } // namespace Types
4122 // Collection of interesting cases below.
4124 // Naive parsing of AST can lead to cycles in processing. Ensure
4125 // self-references don't trigger an endless cycles of AST node processing.
4126 namespace SelfReference {
4127 #if defined(FIRST)
4128 template <template <int> class T> class Wrapper {};
4130 template <int N> class S {
4131 S(Wrapper<::SelfReference::S> &Ref) {}
4134 struct Xx {
4135 struct Yy {
4139 Xx::Xx::Xx::Yy yy;
4141 namespace NNS {
4142 template <typename> struct Foo;
4143 template <template <class> class T = NNS::Foo>
4144 struct NestedNamespaceSpecifier {};
4146 #endif
4147 } // namespace SelfReference
4149 namespace FriendFunction {
4150 #if defined(FIRST)
4151 void F(int = 0);
4152 struct S { friend void F(int); };
4153 #elif defined(SECOND)
4154 void F(int);
4155 struct S { friend void F(int); };
4156 #else
4157 S s;
4158 #endif
4160 #if defined(FIRST)
4161 void G(int = 0);
4162 struct T {
4163 friend void G(int);
4165 private:
4167 #elif defined(SECOND)
4168 void G(int);
4169 struct T {
4170 friend void G(int);
4172 public:
4174 #else
4175 T t;
4176 // expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
4177 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
4178 #endif
4179 } // namespace FriendFunction
4181 namespace ImplicitDecl {
4182 #if defined(FIRST)
4183 struct S { };
4184 void S_Constructors() {
4185 // Trigger creation of implicit contructors
4186 S foo;
4187 S bar = foo;
4188 S baz(bar);
4190 #elif defined(SECOND)
4191 struct S { };
4192 #else
4193 S s;
4194 #endif
4196 #if defined(FIRST)
4197 struct T {
4198 private:
4200 void T_Constructors() {
4201 // Trigger creation of implicit contructors
4202 T foo;
4203 T bar = foo;
4204 T baz(bar);
4206 #elif defined(SECOND)
4207 struct T {
4208 public:
4210 #else
4211 T t;
4212 // expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
4213 // expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
4214 #endif
4216 } // namespace ImplicitDecl
4218 namespace TemplatedClass {
4219 #if defined(FIRST)
4220 template <class>
4221 struct S {};
4222 #elif defined(SECOND)
4223 template <class>
4224 struct S {};
4225 #else
4226 S<int> s;
4227 #endif
4229 #if defined(FIRST)
4230 template <class>
4231 struct T {
4232 private:
4234 #elif defined(SECOND)
4235 template <class>
4236 struct T {
4237 public:
4239 #else
4240 T<int> t;
4241 // expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
4242 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
4243 #endif
4244 } // namespace TemplatedClass
4246 namespace TemplateClassWithField {
4247 #if defined(FIRST)
4248 template <class A>
4249 struct S {
4250 A a;
4252 #elif defined(SECOND)
4253 template <class A>
4254 struct S {
4255 A a;
4257 #else
4258 S<int> s;
4259 #endif
4261 #if defined(FIRST)
4262 template <class A>
4263 struct T {
4264 A a;
4266 private:
4268 #elif defined(SECOND)
4269 template <class A>
4270 struct T {
4271 A a;
4273 public:
4275 #else
4276 T<int> t;
4277 // expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
4278 // expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
4279 #endif
4280 } // namespace TemplateClassWithField
4282 namespace TemplateClassWithTemplateField {
4283 #if defined(FIRST)
4284 template <class A>
4285 class WrapperS;
4286 template <class A>
4287 struct S {
4288 WrapperS<A> a;
4290 #elif defined(SECOND)
4291 template <class A>
4292 class WrapperS;
4293 template <class A>
4294 struct S {
4295 WrapperS<A> a;
4297 #else
4298 template <class A>
4299 class WrapperS{};
4300 S<int> s;
4301 #endif
4303 #if defined(FIRST)
4304 template <class A>
4305 class WrapperT;
4306 template <class A>
4307 struct T {
4308 WrapperT<A> a;
4310 public:
4312 #elif defined(SECOND)
4313 template <class A>
4314 class WrapperT;
4315 template <class A>
4316 struct T {
4317 WrapperT<A> a;
4319 private:
4321 #else
4322 template <class A>
4323 class WrapperT{};
4324 T<int> t;
4325 // expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4326 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4327 #endif
4328 } // namespace TemplateClassWithTemplateField
4330 namespace EnumWithForwardDeclaration {
4331 #if defined(FIRST)
4332 enum E : int;
4333 struct S {
4334 void get(E) {}
4336 #elif defined(SECOND)
4337 enum E : int { A, B };
4338 struct S {
4339 void get(E) {}
4341 #else
4342 S s;
4343 #endif
4345 #if defined(FIRST)
4346 struct T {
4347 void get(E) {}
4348 public:
4350 #elif defined(SECOND)
4351 struct T {
4352 void get(E) {}
4353 private:
4355 #else
4356 T t;
4357 // expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4358 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4359 #endif
4360 } // namespace EnumWithForwardDeclaration
4362 namespace StructWithForwardDeclaration {
4363 #if defined(FIRST)
4364 struct P {};
4365 struct S {
4366 struct P *ptr;
4368 #elif defined(SECOND)
4369 struct S {
4370 struct P *ptr;
4372 #else
4373 S s;
4374 #endif
4376 #if defined(FIRST)
4377 struct Q {};
4378 struct T {
4379 struct Q *ptr;
4380 public:
4382 #elif defined(SECOND)
4383 struct T {
4384 struct Q *ptr;
4385 private:
4387 #else
4388 T t;
4389 // expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4390 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4391 #endif
4392 } // namespace StructWithForwardDeclaration
4394 namespace StructWithForwardDeclarationNoDefinition {
4395 #if defined(FIRST)
4396 struct P;
4397 struct S {
4398 struct P *ptr;
4400 #elif defined(SECOND)
4401 struct S {
4402 struct P *ptr;
4404 #else
4405 S s;
4406 #endif
4408 #if defined(FIRST)
4409 struct Q;
4410 struct T {
4411 struct Q *ptr;
4413 public:
4415 #elif defined(SECOND)
4416 struct T {
4417 struct Q *ptr;
4419 private:
4421 #else
4422 T t;
4423 // expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
4424 // expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
4425 #endif
4426 } // namespace StructWithForwardDeclarationNoDefinition
4428 namespace LateParsedDefaultArgument {
4429 #if defined(FIRST)
4430 template <typename T>
4431 struct S {
4432 struct R {
4433 void foo(T x = 0) {}
4436 #elif defined(SECOND)
4437 #else
4438 void run() {
4439 S<int>::R().foo();
4441 #endif
4442 } // namespace LateParsedDefaultArgument
4444 namespace LateParsedDefaultArgument {
4445 #if defined(FIRST)
4446 template <typename alpha> struct Bravo {
4447 void charlie(bool delta = false) {}
4449 typedef Bravo<char> echo;
4450 echo foxtrot;
4452 Bravo<char> golf;
4453 #elif defined(SECOND)
4454 #else
4455 #endif
4456 } // LateParsedDefaultArgument
4458 namespace DifferentParameterNameInTemplate {
4459 #if defined(FIRST) || defined(SECOND)
4460 template <typename T>
4461 struct S {
4462 typedef T Type;
4464 static void Run(const Type *name_one);
4467 template <typename T>
4468 void S<T>::Run(const T *name_two) {}
4470 template <typename T>
4471 struct Foo {
4472 ~Foo() { Handler::Run(nullptr); }
4473 Foo() {}
4475 class Handler : public S<T> {};
4477 void Get(typename Handler::Type *x = nullptr) {}
4478 void Add() { Handler::Run(nullptr); }
4480 #endif
4482 #if defined(FIRST)
4483 struct Beta;
4485 struct Alpha {
4486 Alpha();
4487 void Go() { betas.Get(); }
4488 Foo<Beta> betas;
4491 #elif defined(SECOND)
4492 struct Beta {};
4494 struct BetaHelper {
4495 void add_Beta() { betas.Add(); }
4496 Foo<Beta> betas;
4499 #else
4500 Alpha::Alpha() {}
4501 #endif
4502 } // DifferentParameterNameInTemplate
4504 namespace ParameterTest {
4505 #if defined(FIRST)
4506 class X {};
4507 template <typename G>
4508 class S {
4509 public:
4510 typedef G Type;
4511 static inline G *Foo(const G *a, int * = nullptr);
4514 template<typename G>
4515 G* S<G>::Foo(const G* aaaa, int*) {}
4516 #elif defined(SECOND)
4517 template <typename G>
4518 class S {
4519 public:
4520 typedef G Type;
4521 static inline G *Foo(const G *a, int * = nullptr);
4524 template<typename G>
4525 G* S<G>::Foo(const G* asdf, int*) {}
4526 #else
4527 S<X> s;
4528 // expected-error@first.h:* {{'ParameterTest::S::Foo' has different definitions in different modules; definition in module 'FirstModule' first difference is 1st parameter with name 'aaaa'}}
4529 // expected-note@second.h:* {{but in 'SecondModule' found 1st parameter with name 'asdf'}}
4530 #endif
4531 } // ParameterTest
4533 namespace MultipleTypedefs {
4534 #if defined(FIRST)
4535 typedef int B1;
4536 typedef B1 A1;
4537 struct S1 {
4538 A1 x;
4540 #elif defined(SECOND)
4541 typedef int A1;
4542 struct S1 {
4543 A1 x;
4545 #else
4546 S1 s1;
4547 #endif
4549 #if defined(FIRST)
4550 struct T2 { int x; };
4551 typedef T2 B2;
4552 typedef B2 A2;
4553 struct S2 {
4554 T2 x;
4556 #elif defined(SECOND)
4557 struct T2 { int x; };
4558 typedef T2 A2;
4559 struct S2 {
4560 T2 x;
4562 #else
4563 S2 s2;
4564 #endif
4566 #if defined(FIRST)
4567 using A3 = const int;
4568 using B3 = volatile A3;
4569 struct S3 {
4570 B3 x = 1;
4572 #elif defined(SECOND)
4573 using A3 = volatile const int;
4574 using B3 = A3;
4575 struct S3 {
4576 B3 x = 1;
4578 #else
4579 S3 s3;
4580 #endif
4582 #if defined(FIRST)
4583 using A4 = int;
4584 using B4 = A4;
4585 struct S4 {
4586 B4 x;
4588 #elif defined(SECOND)
4589 using A4 = int;
4590 using B4 = ::MultipleTypedefs::A4;
4591 struct S4 {
4592 B4 x;
4594 #else
4595 S4 s4;
4596 #endif
4598 #if defined(FIRST)
4599 using A5 = int;
4600 using B5 = MultipleTypedefs::A5;
4601 struct S5 {
4602 B5 x;
4604 #elif defined(SECOND)
4605 using A5 = int;
4606 using B5 = ::MultipleTypedefs::A5;
4607 struct S5 {
4608 B5 x;
4610 #else
4611 S5 s5;
4612 #endif
4613 } // MultipleTypedefs
4615 namespace DefaultArguments {
4616 #if defined(FIRST)
4617 template <typename T>
4618 struct S {
4619 struct R {
4620 void foo(T x = 0);
4623 #elif defined(SECOND)
4624 template <typename T>
4625 struct S {
4626 struct R {
4627 void foo(T x = 1);
4630 #else
4631 void run() {
4632 S<int>::R().foo();
4634 // 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}}
4635 // expected-note@first.h:* {{but in 'FirstModule' found method 'foo' with 1st parameter with a different default argument}}
4636 #endif
4638 #if defined(FIRST)
4639 template <typename alpha> struct Bravo {
4640 void charlie(bool delta = false);
4642 typedef Bravo<char> echo;
4643 echo foxtrot;
4644 #elif defined(SECOND)
4645 template <typename alpha> struct Bravo {
4646 void charlie(bool delta = (false));
4648 typedef Bravo<char> echo;
4649 echo foxtrot;
4650 #else
4651 Bravo<char> golf;
4652 // 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}}
4653 // expected-note@first.h:* {{but in 'FirstModule' found method 'charlie' with 1st parameter with a different default argument}}
4654 #endif
4655 } // namespace DefaultArguments
4657 namespace FunctionDecl {
4658 #if defined(FIRST)
4659 struct S1 {};
4660 S1 s1a;
4661 #elif defined(SECOND)
4662 struct S1 {};
4663 #else
4664 S1 s1;
4665 #endif
4667 #if defined(FIRST)
4668 struct S2 {
4669 S2() = default;
4671 S2 s2a = S2();
4672 #elif defined(SECOND)
4673 struct S2 {
4674 S2() = default;
4676 #else
4677 S2 s2;
4678 #endif
4680 #if defined(FIRST)
4681 struct S3 {
4682 S3() = delete;
4684 S3* s3c;
4685 #elif defined(SECOND)
4686 struct S3 {
4687 S3() = delete;
4689 #else
4690 S3* s3;
4691 #endif
4693 #if defined(FIRST) || defined(SECOND)
4694 int F1(int x, float y = 2.7) { return 1; }
4695 #else
4696 int I1 = F1(1);
4697 #endif
4699 #if defined(FIRST)
4700 int F2() { return 1; }
4701 #elif defined(SECOND)
4702 double F2() { return 1; }
4703 #else
4704 int I2 = F2();
4705 // expected-error@-1 {{call to 'F2' is ambiguous}}
4706 // expected-note@first.h:* {{candidate function}}
4707 // expected-note@second.h:* {{candidate function}}
4708 #endif
4710 #if defined(FIRST)
4711 int F3(float) { return 1; }
4712 #elif defined(SECOND)
4713 int F3(double) { return 1; }
4714 #else
4715 int I3 = F3(1);
4716 // expected-error@-1 {{call to 'F3' is ambiguous}}
4717 // expected-note@first.h:* {{candidate function}}
4718 // expected-note@second.h:* {{candidate function}}
4719 #endif
4721 #if defined(FIRST)
4722 int F4(int x) { return 1; }
4723 #elif defined(SECOND)
4724 int F4(int y) { return 1; }
4725 #else
4726 int I4 = F4(1);
4727 // expected-error@second.h:* {{'FunctionDecl::F4' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with name 'y'}}
4728 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with name 'x'}}
4729 #endif
4731 #if defined(FIRST)
4732 int F5(int x) { return 1; }
4733 #elif defined(SECOND)
4734 int F5(int x = 1) { return 1; }
4735 #else
4736 int I5 = F6(1);
4737 // 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}}
4738 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a default argument}}
4739 #endif
4741 #if defined(FIRST)
4742 int F6(int x = 2) { return 1; }
4743 #elif defined(SECOND)
4744 int F6(int x = 1) { return 1; }
4745 #else
4746 int I6 = F6(1);
4747 // 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}}
4748 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with a different default argument}}
4749 #endif
4751 using I = int;
4752 #if defined(FIRST)
4753 I F7() { return 0; }
4754 #elif defined(SECOND)
4755 int F7() { return 0; }
4756 #else
4757 int I7 = F7();
4758 // expected-error@second.h:* {{'FunctionDecl::F7' has different definitions in different modules; definition in module 'SecondModule' first difference is return type is 'int'}}
4759 // expected-note@first.h:* {{but in 'FirstModule' found different return type 'I' (aka 'int')}}
4760 #endif
4762 #if defined(FIRST)
4763 int F8(int) { return 0; }
4764 #elif defined(SECOND)
4765 int F8(I) { return 0; }
4766 #else
4767 int I8 = F8(1);
4768 // expected-error@second.h:* {{'FunctionDecl::F8' has different definitions in different modules; definition in module 'SecondModule' first difference is 1st parameter with type 'I' (aka 'int')}}
4769 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int'}}
4770 #endif
4772 #if defined(FIRST)
4773 int F9(int[1]) { return 0; }
4774 #elif defined(SECOND)
4775 int F9(int[2]) { return 0; }
4776 #else
4777 int I9 = F9(nullptr);
4778 // 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]'}}
4779 // expected-note@first.h:* {{but in 'FirstModule' found 1st parameter with type 'int *' decayed from 'int[1]'}}
4780 #endif
4782 #if defined(FIRST)
4783 int F10() { return 1; }
4784 #elif defined(SECOND)
4785 int F10() { return 2; }
4786 #else
4787 int I10 = F10();
4788 #endif
4789 // expected-error@second.h:* {{'FunctionDecl::F10' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
4790 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
4792 #if defined(FIRST)
4793 struct S11 {
4794 template <int> void foo();
4796 #elif defined(SECOND)
4797 struct S11 {
4798 template <int> void foo();
4800 template <int> void S11::foo() {}
4801 #else
4802 S11 s11;
4803 #endif
4805 #if defined(FIRST)
4806 struct S12 {
4807 void foo(int x);
4809 #elif defined(SECOND)
4810 struct S12 {
4811 void foo(int x);
4813 void S12::foo(int y) {}
4814 #else
4815 S12 s12;
4816 #endif
4818 #if defined(FIRST)
4819 struct S13 {
4820 void foo(int x);
4822 void S13::foo(int y) {}
4823 #elif defined(SECOND)
4824 struct S13 {
4825 void foo(int x);
4827 void S13::foo(int y) {}
4828 #else
4829 S13 s13;
4830 #endif
4831 } // namespace FunctionDecl
4833 namespace DeclTemplateArguments {
4834 #if defined(FIRST)
4835 int foo() { return 1; }
4836 int bar() { return foo(); }
4837 #elif defined(SECOND)
4838 template <class T = int>
4839 int foo() { return 2; }
4840 int bar() { return foo<>(); }
4841 #else
4842 int num = bar();
4843 // expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
4844 // expected-note@first.h:* {{but in 'FirstModule' found a different body}}
4845 #endif
4848 namespace FunctionProtoTypeDecay {
4849 #if defined(FIRST)
4850 struct S1 {
4851 struct X {};
4852 using Y = X(X());
4854 #elif defined(SECOND)
4855 struct S1 {
4856 struct X {};
4857 using Y = X(X(X()));
4859 #else
4860 S1 s1;
4861 // expected-error@first.h:* {{'FunctionProtoTypeDecay::S1::Y' from module 'FirstModule' is not present in definition of 'FunctionProtoTypeDecay::S1' in module 'SecondModule'}}
4862 // expected-note@second.h:* {{declaration of 'Y' does not match}}
4863 #endif
4865 #if defined(FIRST)
4866 struct S2 {
4867 struct X {};
4868 using Y =
4869 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
4870 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
4871 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
4872 X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(X(
4873 ))))))))))))))))
4874 ))))))))))))))))
4875 ))))))))))))))))
4876 ))))))))))))))));
4878 #elif defined(SECOND)
4879 #else
4880 S2 s2;
4881 #endif
4884 namespace TypedefStruct {
4885 #if defined(FIRST)
4886 struct T1;
4887 class S1 {
4888 T1* t;
4890 #elif defined(SECOND)
4891 typedef struct T1 {} T1;
4892 class S1 {
4893 T1* t;
4895 #else
4896 S1 s1;
4897 #endif
4899 #if defined(FIRST)
4900 struct T2;
4901 class S2 {
4902 const T2* t = nullptr;
4904 #elif defined(SECOND)
4905 typedef struct T2 {} T2;
4906 class S2 {
4907 const T2* t = nullptr;
4909 #else
4910 S2 s2;
4911 #endif
4913 #if defined(FIRST)
4914 struct T3;
4915 class S3 {
4916 T3* const t = nullptr;
4918 #elif defined(SECOND)
4919 typedef struct T3 {} T3;
4920 class S3 {
4921 T3* const t = nullptr;
4923 #else
4924 S3 s3;
4925 #endif
4927 #if defined(FIRST)
4928 namespace NS4 {
4929 struct T4;
4930 } // namespace NS4
4931 class S4 {
4932 NS4::T4* t = 0;
4934 #elif defined(SECOND)
4935 namespace NS4 {
4936 typedef struct T4 {} T4;
4937 } // namespace NS4
4938 class S4 {
4939 NS4::T4* t = 0;
4941 #else
4942 S4 s4;
4943 #endif
4945 #if defined(FIRST)
4946 namespace NS5 {
4947 struct T5;
4948 } // namespace NS5
4949 class S5 {
4950 NS5::T5* t = 0;
4952 #elif defined(SECOND)
4953 namespace NS5 {
4954 typedef struct T5_Other {} T5;
4955 } // namespace NS4
4956 class S5 {
4957 NS5::T5* t = 0;
4959 #else
4960 S5 s5;
4961 // expected-error@first.h:* {{'TypedefStruct::S5::t' from module 'FirstModule' is not present in definition of 'TypedefStruct::S5' in module 'SecondModule'}}
4962 // expected-note@second.h:* {{declaration of 't' does not match}}
4963 #endif
4964 } // namespace TypedefStruct
4966 #if defined (FIRST)
4967 typedef int T;
4968 namespace A {
4969 struct X { T n; };
4971 #elif defined(SECOND)
4972 namespace A {
4973 typedef int T;
4974 struct X { T n; };
4976 #else
4977 A::X x;
4978 #endif
4980 // Keep macros contained to one file.
4981 #ifdef FIRST
4982 #undef FIRST
4983 #endif
4985 #ifdef SECOND
4986 #undef SECOND
4987 #endif
4989 #ifdef ACCESS
4990 #undef ACCESS
4991 #endif