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