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 // Build module map file
16 // RUN: echo "module FirstModule {"     >> %t/Inputs/module.map
17 // RUN: echo "    header \"first.h\""   >> %t/Inputs/module.map
18 // RUN: echo "}"                        >> %t/Inputs/module.map
19 // RUN: echo "module SecondModule {"    >> %t/Inputs/module.map
20 // RUN: echo "    header \"second.h\""  >> %t/Inputs/module.map
21 // RUN: echo "}"                        >> %t/Inputs/module.map
22 
23 // Run test
24 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z
25 
26 #if !defined(FIRST) && !defined(SECOND)
27 #include "first.h"
28 #include "second.h"
29 #endif
30 
31 namespace AccessSpecifiers {
32 #if defined(FIRST)
33 struct S1 {
34 };
35 #elif defined(SECOND)
36 struct S1 {
37   private:
38 };
39 #else
40 S1 s1;
41 // [email protected]:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
42 // [email protected]:* {{but in 'FirstModule' found end of class}}
43 #endif
44 
45 #if defined(FIRST)
46 struct S2 {
47   public:
48 };
49 #elif defined(SECOND)
50 struct S2 {
51   protected:
52 };
53 #else
54 S2 s2;
55 // [email protected]:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}}
56 // [email protected]:* {{but in 'FirstModule' found public access specifier}}
57 #endif
58 } // namespace AccessSpecifiers
59 
60 namespace StaticAssert {
61 #if defined(FIRST)
62 struct S1 {
63   static_assert(1 == 1, "First");
64 };
65 #elif defined(SECOND)
66 struct S1 {
67   static_assert(1 == 1, "Second");
68 };
69 #else
70 S1 s1;
71 // [email protected]:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}}
72 // [email protected]:* {{but in 'FirstModule' found static assert with different message}}
73 #endif
74 
75 #if defined(FIRST)
76 struct S2 {
77   static_assert(2 == 2, "Message");
78 };
79 #elif defined(SECOND)
80 struct S2 {
81   static_assert(2 == 2);
82 };
83 #else
84 S2 s2;
85 // [email protected]:* {{'StaticAssert::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with no message}}
86 // [email protected]:* {{but in 'FirstModule' found static assert with message}}
87 #endif
88 
89 #if defined(FIRST)
90 struct S3 {
91   static_assert(3 == 3, "Message");
92 };
93 #elif defined(SECOND)
94 struct S3 {
95   static_assert(3 != 4, "Message");
96 };
97 #else
98 S3 s3;
99 // [email protected]:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}}
100 // [email protected]:* {{but in 'FirstModule' found static assert with different condition}}
101 #endif
102 
103 #if defined(FIRST)
104 struct S4 {
105   static_assert(4 == 4, "Message");
106 };
107 #elif defined(SECOND)
108 struct S4 {
109   public:
110 };
111 #else
112 S4 s4;
113 // [email protected]:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
114 // [email protected]:* {{but in 'FirstModule' found static assert}}
115 #endif
116 }
117 
118 namespace Field {
119 #if defined(FIRST)
120 struct S1 {
121   int x;
122   private:
123   int y;
124 };
125 #elif defined(SECOND)
126 struct S1 {
127   int x;
128   int y;
129 };
130 #else
131 S1 s1;
132 // [email protected]:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
133 // [email protected]:* {{but in 'FirstModule' found private access specifier}}
134 #endif
135 
136 #if defined(FIRST)
137 struct S2 {
138   int x;
139   int y;
140 };
141 #elif defined(SECOND)
142 struct S2 {
143   int y;
144   int x;
145 };
146 #else
147 S2 s2;
148 // [email protected]:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
149 // [email protected]:* {{but in 'FirstModule' found field 'x'}}
150 #endif
151 
152 #if defined(FIRST)
153 struct S3 {
154   double x;
155 };
156 #elif defined(SECOND)
157 struct S3 {
158   int x;
159 };
160 #else
161 S3 s3;
162 // [email protected]:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}}
163 // [email protected]:* {{declaration of 'x' does not match}}
164 #endif
165 
166 #if defined(FIRST)
167 typedef int A;
168 struct S4 {
169   A x;
170 };
171 
172 struct S5 {
173   A x;
174 };
175 #elif defined(SECOND)
176 typedef int B;
177 struct S4 {
178   B x;
179 };
180 
181 struct S5 {
182   int x;
183 };
184 #else
185 S4 s4;
186 // [email protected]:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'Field::B' (aka 'int')}}
187 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
188 
189 S5 s5;
190 // [email protected]:* {{'Field::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}}
191 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'Field::A' (aka 'int')}}
192 #endif
193 
194 #if defined(FIRST)
195 struct S6 {
196   unsigned x;
197 };
198 #elif defined(SECOND)
199 struct S6 {
200   unsigned x : 1;
201 };
202 #else
203 S6 s6;
204 // [email protected]:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}}
205 // [email protected]:* {{but in 'FirstModule' found non-bitfield 'x'}}
206 #endif
207 
208 #if defined(FIRST)
209 struct S7 {
210   unsigned x : 2;
211 };
212 #elif defined(SECOND)
213 struct S7 {
214   unsigned x : 1;
215 };
216 #else
217 S7 s7;
218 // [email protected]:* {{'Field::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}}
219 // [email protected]:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
220 #endif
221 
222 #if defined(FIRST)
223 struct S8 {
224   unsigned x : 2;
225 };
226 #elif defined(SECOND)
227 struct S8 {
228   unsigned x : 1 + 1;
229 };
230 #else
231 S8 s8;
232 // [email protected]:* {{'Field::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x' with one width expression}}
233 // [email protected]:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
234 #endif
235 
236 #if defined(FIRST)
237 struct S9 {
238   mutable int x;
239 };
240 #elif defined(SECOND)
241 struct S9 {
242   int x;
243 };
244 #else
245 S9 s9;
246 // [email protected]:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
247 // [email protected]:* {{but in 'FirstModule' found mutable field 'x'}}
248 #endif
249 
250 #if defined(FIRST)
251 struct S10 {
252   unsigned x = 5;
253 };
254 #elif defined(SECOND)
255 struct S10 {
256   unsigned x;
257 };
258 #else
259 S10 s10;
260 // [email protected]:* {{'Field::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with no initalizer}}
261 // [email protected]:* {{but in 'FirstModule' found field 'x' with an initializer}}
262 #endif
263 
264 #if defined(FIRST)
265 struct S11 {
266   unsigned x = 5;
267 };
268 #elif defined(SECOND)
269 struct S11 {
270   unsigned x = 7;
271 };
272 #else
273 S11 s11;
274 // [email protected]:* {{'Field::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}}
275 // [email protected]:* {{but in 'FirstModule' found field 'x' with a different initializer}}
276 #endif
277 
278 #if defined(FIRST)
279 struct S12 {
280   unsigned x[5];
281 };
282 #elif defined(SECOND)
283 struct S12 {
284   unsigned x[7];
285 };
286 #else
287 S12 s12;
288 // [email protected]:* {{'Field::S12::x' from module 'FirstModule' is not present in definition of 'Field::S12' in module 'SecondModule'}}
289 // [email protected]:* {{declaration of 'x' does not match}}
290 #endif
291 
292 #if defined(FIRST)
293 struct S13 {
294   unsigned x[7];
295 };
296 #elif defined(SECOND)
297 struct S13 {
298   double x[7];
299 };
300 #else
301 S13 s13;
302 // [email protected]:* {{'Field::S13::x' from module 'FirstModule' is not present in definition of 'Field::S13' in module 'SecondModule'}}
303 // [email protected]:* {{declaration of 'x' does not match}}
304 #endif
305 }  // namespace Field
306 
307 namespace Method {
308 #if defined(FIRST)
309 struct S1 {
310   void A() {}
311 };
312 #elif defined(SECOND)
313 struct S1 {
314   private:
315   void A() {}
316 };
317 #else
318 S1 s1;
319 // [email protected]:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
320 // [email protected]:* {{but in 'FirstModule' found method}}
321 #endif
322 
323 #if defined(FIRST)
324 struct S2 {
325   void A() {}
326   void B() {}
327 };
328 #elif defined(SECOND)
329 struct S2 {
330   void B() {}
331   void A() {}
332 };
333 #else
334 S2 s2;
335 // [email protected]:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
336 // [email protected]:* {{but in 'FirstModule' found method 'A'}}
337 #endif
338 
339 #if defined(FIRST)
340 struct S3 {
341   static void A() {}
342   void A(int) {}
343 };
344 #elif defined(SECOND)
345 struct S3 {
346   void A(int) {}
347   static void A() {}
348 };
349 #else
350 S3 s3;
351 // [email protected]:* {{'Method::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not static}}
352 // [email protected]:* {{but in 'FirstModule' found method 'A' is static}}
353 #endif
354 
355 #if defined(FIRST)
356 struct S4 {
357   virtual void A() {}
358   void B() {}
359 };
360 #elif defined(SECOND)
361 struct S4 {
362   void A() {}
363   virtual void B() {}
364 };
365 #else
366 S4 s4;
367 // [email protected]:* {{'Method::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not virtual}}
368 // [email protected]:* {{but in 'FirstModule' found method 'A' is virtual}}
369 #endif
370 
371 #if defined(FIRST)
372 struct S5 {
373   virtual void A() = 0;
374   virtual void B() {};
375 };
376 #elif defined(SECOND)
377 struct S5 {
378   virtual void A() {}
379   virtual void B() = 0;
380 };
381 #else
382 S5 *s5;
383 // [email protected]:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
384 // [email protected]:* {{but in 'FirstModule' found method 'A' is pure virtual}}
385 #endif
386 
387 #if defined(FIRST)
388 struct S6 {
389   inline void A() {}
390 };
391 #elif defined(SECOND)
392 struct S6 {
393   void A() {}
394 };
395 #else
396 S6 s6;
397 // [email protected]:* {{'Method::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not inline}}
398 // [email protected]:* {{but in 'FirstModule' found method 'A' is inline}}
399 #endif
400 
401 #if defined(FIRST)
402 struct S7 {
403   void A() volatile {}
404   void A() {}
405 };
406 #elif defined(SECOND)
407 struct S7 {
408   void A() {}
409   void A() volatile {}
410 };
411 #else
412 S7 s7;
413 // [email protected]:* {{'Method::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not volatile}}
414 // [email protected]:* {{but in 'FirstModule' found method 'A' is volatile}}
415 #endif
416 
417 #if defined(FIRST)
418 struct S8 {
419   void A() const {}
420   void A() {}
421 };
422 #elif defined(SECOND)
423 struct S8 {
424   void A() {}
425   void A() const {}
426 };
427 #else
428 S8 s8;
429 // [email protected]:* {{'Method::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is not const}}
430 // [email protected]:* {{but in 'FirstModule' found method 'A' is const}}
431 #endif
432 
433 #if defined(FIRST)
434 struct S9 {
435   void A(int x) {}
436   void A(int x, int y) {}
437 };
438 #elif defined(SECOND)
439 struct S9 {
440   void A(int x, int y) {}
441   void A(int x) {}
442 };
443 #else
444 S9 s9;
445 // [email protected]:* {{'Method::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' that has 2 parameters}}
446 // [email protected]:* {{but in 'FirstModule' found method 'A' that has 1 parameter}}
447 #endif
448 
449 #if defined(FIRST)
450 struct S10 {
451   void A(int x) {}
452   void A(float x) {}
453 };
454 #elif defined(SECOND)
455 struct S10 {
456   void A(float x) {}
457   void A(int x) {}
458 };
459 #else
460 S10 s10;
461 // [email protected]:* {{'Method::S10' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter of type 'float'}}
462 // [email protected]:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int'}}
463 #endif
464 
465 #if defined(FIRST)
466 struct S11 {
467   void A(int x) {}
468 };
469 #elif defined(SECOND)
470 struct S11 {
471   void A(int y) {}
472 };
473 #else
474 S11 s11;
475 // [email protected]:* {{'Method::S11' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' with 1st parameter named 'y'}}
476 // [email protected]:* {{but in 'FirstModule' found method 'A' with 1st parameter named 'x'}}
477 #endif
478 
479 #if defined(FIRST)
480 struct S12 {
481   void A(int x) {}
482 };
483 #elif defined(SECOND)
484 struct S12 {
485   void A(int x = 1) {}
486 };
487 #else
488 S12 s12;
489 // TODO: This should produce an error.
490 #endif
491 
492 #if defined(FIRST)
493 struct S13 {
494   void A(int x = 1 + 0) {}
495 };
496 #elif defined(SECOND)
497 struct S13 {
498   void A(int x = 1) {}
499 };
500 #else
501 S13 s13;
502 // TODO: This should produce an error.
503 #endif
504 
505 #if defined(FIRST)
506 struct S14 {
507   void A(int x[2]) {}
508 };
509 #elif defined(SECOND)
510 struct S14 {
511   void A(int x[3]) {}
512 };
513 #else
514 S14 s14;
515 // [email protected]:* {{'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]'}}
516 // [email protected]:* {{but in 'FirstModule' found method 'A' with 1st parameter of type 'int *' decayed from 'int [2]'}}
517 #endif
518 }  // namespace Method
519 
520 // Naive parsing of AST can lead to cycles in processing.  Ensure
521 // self-references don't trigger an endless cycles of AST node processing.
522 namespace SelfReference {
523 #if defined(FIRST)
524 template <template <int> class T> class Wrapper {};
525 
526 template <int N> class S {
527   S(Wrapper<::SelfReference::S> &Ref) {}
528 };
529 
530 struct Xx {
531   struct Yy {
532   };
533 };
534 
535 Xx::Xx::Xx::Yy yy;
536 
537 namespace NNS {
538 template <typename> struct Foo;
539 template <template <class> class T = NNS::Foo>
540 struct NestedNamespaceSpecifier {};
541 }
542 #endif
543 }  // namespace SelfReference
544 
545 namespace TypeDef {
546 #if defined(FIRST)
547 struct S1 {
548   typedef int a;
549 };
550 #elif defined(SECOND)
551 struct S1 {
552   typedef double a;
553 };
554 #else
555 S1 s1;
556 // [email protected]:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
557 // [email protected]:* {{declaration of 'a' does not match}}
558 #endif
559 
560 #if defined(FIRST)
561 struct S2 {
562   typedef int a;
563 };
564 #elif defined(SECOND)
565 struct S2 {
566   typedef int b;
567 };
568 #else
569 S2 s2;
570 // [email protected]:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
571 // [email protected]:* {{definition has no member 'a'}}
572 #endif
573 
574 #if defined(FIRST)
575 typedef int T;
576 struct S3 {
577   typedef T a;
578 };
579 #elif defined(SECOND)
580 typedef double T;
581 struct S3 {
582   typedef T a;
583 };
584 #else
585 S3 s3;
586 // [email protected]:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
587 // [email protected]:* {{declaration of 'a' does not match}}
588 #endif
589 }  // namespace TypeDef
590 
591 namespace Using {
592 #if defined(FIRST)
593 struct S1 {
594   using a = int;
595 };
596 #elif defined(SECOND)
597 struct S1 {
598   using a = double;
599 };
600 #else
601 S1 s1;
602 // [email protected]:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
603 // [email protected]:* {{declaration of 'a' does not match}}
604 #endif
605 
606 #if defined(FIRST)
607 struct S2 {
608   using a = int;
609 };
610 #elif defined(SECOND)
611 struct S2 {
612   using b = int;
613 };
614 #else
615 S2 s2;
616 // [email protected]:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
617 // [email protected]:* {{definition has no member 'a'}}
618 #endif
619 
620 #if defined(FIRST)
621 typedef int T;
622 struct S3 {
623   using a = T;
624 };
625 #elif defined(SECOND)
626 typedef double T;
627 struct S3 {
628   using a = T;
629 };
630 #else
631 S3 s3;
632 // [email protected]:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
633 // [email protected]:* {{declaration of 'a' does not match}}
634 #endif
635 }  // namespace Using
636 
637 namespace RecordType {
638 #if defined(FIRST)
639 struct B1 {};
640 struct S1 {
641   B1 x;
642 };
643 #elif defined(SECOND)
644 struct A1 {};
645 struct S1 {
646   A1 x;
647 };
648 #else
649 S1 s1;
650 // [email protected]:* {{'RecordType::S1::x' from module 'FirstModule' is not present in definition of 'RecordType::S1' in module 'SecondModule'}}
651 // [email protected]:* {{declaration of 'x' does not match}}
652 #endif
653 }
654 
655 namespace DependentType {
656 #if defined(FIRST)
657 template <class T>
658 class S1 {
659   typename T::typeA x;
660 };
661 #elif defined(SECOND)
662 template <class T>
663 class S1 {
664   typename T::typeB x;
665 };
666 #else
667 template<class T>
668 using U1 = S1<T>;
669 // [email protected]:* {{'DependentType::S1::x' from module 'FirstModule' is not present in definition of 'S1<T>' in module 'SecondModule'}}
670 // [email protected]:* {{declaration of 'x' does not match}}
671 #endif
672 }
673 
674 namespace ElaboratedType {
675 #if defined(FIRST)
676 namespace N1 { using type = double; }
677 struct S1 {
678   N1::type x;
679 };
680 #elif defined(SECOND)
681 namespace N1 { using type = int; }
682 struct S1 {
683   N1::type x;
684 };
685 #else
686 S1 s1;
687 // [email protected]:* {{'ElaboratedType::S1::x' from module 'FirstModule' is not present in definition of 'ElaboratedType::S1' in module 'SecondModule'}}
688 // [email protected]:* {{declaration of 'x' does not match}}
689 #endif
690 }
691 
692 namespace Enum {
693 #if defined(FIRST)
694 enum A1 {};
695 struct S1 {
696   A1 x;
697 };
698 #elif defined(SECOND)
699 enum A2 {};
700 struct S1 {
701   A2 x;
702 };
703 #else
704 S1 s1;
705 // [email protected]:* {{'Enum::S1::x' from module 'FirstModule' is not present in definition of 'Enum::S1' in module 'SecondModule'}}
706 // [email protected]:* {{declaration of 'x' does not match}}
707 #endif
708 }
709 
710 namespace NestedNamespaceSpecifier {
711 #if defined(FIRST)
712 namespace LevelA1 {
713 using Type = int;
714 }
715 
716 struct S1 {
717   LevelA1::Type x;
718 };
719 # elif defined(SECOND)
720 namespace LevelB1 {
721 namespace LevelC1 {
722 using Type = int;
723 }
724 }
725 
726 struct S1 {
727   LevelB1::LevelC1::Type x;
728 };
729 #else
730 S1 s1;
731 // [email protected]:* {{'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')}}
732 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'LevelA1::Type' (aka 'int')}}
733 #endif
734 
735 #if defined(FIRST)
736 namespace LevelA2 { using Type = int; }
737 struct S2 {
738   LevelA2::Type x;
739 };
740 # elif defined(SECOND)
741 struct S2 {
742   int x;
743 };
744 #else
745 S2 s2;
746 // [email protected]:* {{'NestedNamespaceSpecifier::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'int'}}
747 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'LevelA2::Type' (aka 'int')}}
748 #endif
749 
750 namespace LevelA3 { using Type = int; }
751 namespace LevelB3 { using Type = int; }
752 #if defined(FIRST)
753 struct S3 {
754   LevelA3::Type x;
755 };
756 # elif defined(SECOND)
757 struct S3 {
758   LevelB3::Type x;
759 };
760 #else
761 S3 s3;
762 // [email protected]:* {{'NestedNamespaceSpecifier::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'LevelB3::Type' (aka 'int')}}
763 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'LevelA3::Type' (aka 'int')}}
764 #endif
765 
766 #if defined(FIRST)
767 struct TA4 { using Type = int; };
768 struct S4 {
769   TA4::Type x;
770 };
771 # elif defined(SECOND)
772 struct TB4 { using Type = int; };
773 struct S4 {
774   TB4::Type x;
775 };
776 #else
777 S4 s4;
778 // [email protected]:* {{'NestedNamespaceSpecifier::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'TB4::Type' (aka 'int')}}
779 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'TA4::Type' (aka 'int')}}
780 #endif
781 
782 #if defined(FIRST)
783 struct T5 { using Type = int; };
784 struct S5 {
785   T5::Type x;
786 };
787 # elif defined(SECOND)
788 namespace T5 { using Type = int; };
789 struct S5 {
790   T5::Type x;
791 };
792 #else
793 S5 s5;
794 // [email protected]:* {{'NestedNamespaceSpecifier::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'T5::Type' (aka 'int')}}
795 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'T5::Type' (aka 'int')}}
796 #endif
797 
798 #if defined(FIRST)
799 namespace N6 {using I = int;}
800 struct S6 {
801   NestedNamespaceSpecifier::N6::I x;
802 };
803 # elif defined(SECOND)
804 using I = int;
805 struct S6 {
806   ::NestedNamespaceSpecifier::I x;
807 };
808 #else
809 S6 s6;
810 // [email protected]:* {{'NestedNamespaceSpecifier::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type '::NestedNamespaceSpecifier::I' (aka 'int')}}
811 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'NestedNamespaceSpecifier::N6::I' (aka 'int')}}
812 #endif
813 
814 #if defined(FIRST)
815 template <class T, class U>
816 class S7 {
817   typename T::type *x = {};
818   int z = x->T::foo();
819 };
820 #elif defined(SECOND)
821 template <class T, class U>
822 class S7 {
823   typename T::type *x = {};
824   int z = x->U::foo();
825 };
826 #else
827 template <class T, class U>
828 using U7 = S7<T, U>;
829 // [email protected]:* {{'NestedNamespaceSpecifier::S7' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'z' with an initializer}}
830 // [email protected]:* {{but in 'FirstModule' found field 'z' with a different initializer}}
831 #endif
832 
833 #if defined(FIRST)
834 template <class T>
835 class S8 {
836   int x = T::template X<int>::value;
837 };
838 #elif defined(SECOND)
839 template <class T>
840 class S8 {
841   int x = T::template Y<int>::value;
842 };
843 #else
844 template <class T>
845 using U8 = S8<T>;
846 // [email protected]:* {{'NestedNamespaceSpecifier::S8' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with an initializer}}
847 // [email protected]:* {{but in 'FirstModule' found field 'x' with a different initializer}}
848 #endif
849 
850 #if defined(FIRST)
851 namespace N9 { using I = int; }
852 namespace O9 = N9;
853 struct S9 {
854   O9::I x;
855 };
856 #elif defined(SECOND)
857 namespace N9 { using I = int; }
858 namespace P9 = N9;
859 struct S9 {
860   P9::I x;
861 };
862 #else
863 S9 s9;
864 // [email protected]:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}}
865 // [email protected]:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
866 #endif
867 }
868 
869 // Interesting cases that should not cause errors.  struct S should not error
870 // while struct T should error at the access specifier mismatch at the end.
871 namespace AllDecls {
872 #define CREATE_ALL_DECL_STRUCT(NAME, ACCESS)               \
873   typedef int INT;                                         \
874   struct NAME {                                            \
875   public:                                                  \
876   private:                                                 \
877   protected:                                               \
878     static_assert(1 == 1, "Message");                      \
879     static_assert(2 == 2);                                 \
880                                                            \
881     int x;                                                 \
882     double y;                                              \
883                                                            \
884     INT z;                                                 \
885                                                            \
886     unsigned a : 1;                                        \
887     unsigned b : 2 * 2 + 5 / 2;                            \
888                                                            \
889     mutable int c = sizeof(x + y);                         \
890                                                            \
891     void method() {}                                       \
892     static void static_method() {}                         \
893     virtual void virtual_method() {}                       \
894     virtual void pure_virtual_method() = 0;                \
895     inline void inline_method() {}                         \
896     void volatile_method() volatile {}                     \
897     void const_method() const {}                           \
898                                                            \
899     typedef int typedef_int;                               \
900     using using_int = int;                                 \
901                                                            \
902     void method_one_arg(int x) {}                          \
903     void method_one_arg_default_argument(int x = 5 + 5) {} \
904     void method_decayed_type(int x[5]) {}                  \
905                                                            \
906     int constant_arr[5];                                   \
907                                                            \
908     ACCESS:                                                \
909   };
910 
911 #if defined(FIRST)
912 CREATE_ALL_DECL_STRUCT(S, public)
913 #elif defined(SECOND)
914 CREATE_ALL_DECL_STRUCT(S, public)
915 #else
916 S *s;
917 #endif
918 
919 #if defined(FIRST)
920 CREATE_ALL_DECL_STRUCT(T, private)
921 #elif defined(SECOND)
922 CREATE_ALL_DECL_STRUCT(T, public)
923 #else
924 T *t;
925 // [email protected]:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
926 // [email protected]:* {{but in 'FirstModule' found private access specifier}}
927 #endif
928 }
929 
930 namespace FriendFunction {
931 #if defined(FIRST)
932 void F(int = 0);
933 struct S { friend void F(int); };
934 #elif defined(SECOND)
935 void F(int);
936 struct S { friend void F(int); };
937 #else
938 S s;
939 #endif
940 
941 #if defined(FIRST)
942 void G(int = 0);
943 struct T {
944   friend void G(int);
945 
946   private:
947 };
948 #elif defined(SECOND)
949 void G(int);
950 struct T {
951   friend void G(int);
952 
953   public:
954 };
955 #else
956 T t;
957 // [email protected]:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
958 // [email protected]:* {{but in 'FirstModule' found private access specifier}}
959 #endif
960 }  // namespace FriendFunction
961 
962 namespace ImplicitDecl {
963 #if defined(FIRST)
964 struct S { };
965 void S_Constructors() {
966   // Trigger creation of implicit contructors
967   S foo;
968   S bar = foo;
969   S baz(bar);
970 }
971 #elif defined(SECOND)
972 struct S { };
973 #else
974 S s;
975 #endif
976 
977 #if defined(FIRST)
978 struct T {
979   private:
980 };
981 void T_Constructors() {
982   // Trigger creation of implicit contructors
983   T foo;
984   T bar = foo;
985   T baz(bar);
986 }
987 #elif defined(SECOND)
988 struct T {
989   public:
990 };
991 #else
992 T t;
993 // [email protected]:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
994 // [email protected]:* {{but in 'SecondModule' found public access specifier}}
995 #endif
996 
997 }  // namespace ImplicitDelc
998 
999 namespace TemplatedClass {
1000 #if defined(FIRST)
1001 template <class>
1002 struct S {};
1003 #elif defined(SECOND)
1004 template <class>
1005 struct S {};
1006 #else
1007 S<int> s;
1008 #endif
1009 
1010 #if defined(FIRST)
1011 template <class>
1012 struct T {
1013   private:
1014 };
1015 #elif defined(SECOND)
1016 template <class>
1017 struct T {
1018   public:
1019 };
1020 #else
1021 T<int> t;
1022 // [email protected]:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
1023 // [email protected]:* {{but in 'FirstModule' found private access specifier}}
1024 #endif
1025 }  // namespace TemplatedClass
1026 
1027 namespace TemplateClassWithField {
1028 #if defined(FIRST)
1029 template <class A>
1030 struct S {
1031   A a;
1032 };
1033 #elif defined(SECOND)
1034 template <class A>
1035 struct S {
1036   A a;
1037 };
1038 #else
1039 S<int> s;
1040 #endif
1041 
1042 #if defined(FIRST)
1043 template <class A>
1044 struct T {
1045   A a;
1046 
1047   private:
1048 };
1049 #elif defined(SECOND)
1050 template <class A>
1051 struct T {
1052   A a;
1053 
1054   public:
1055 };
1056 #else
1057 T<int> t;
1058 // [email protected]:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
1059 // [email protected]:* {{but in 'FirstModule' found private access specifier}}
1060 #endif
1061 }  // namespace TemplateClassWithField
1062 
1063 namespace TemplateClassWithTemplateField {
1064 #if defined(FIRST)
1065 template <class A>
1066 class WrapperS;
1067 template <class A>
1068 struct S {
1069   WrapperS<A> a;
1070 };
1071 #elif defined(SECOND)
1072 template <class A>
1073 class WrapperS;
1074 template <class A>
1075 struct S {
1076   WrapperS<A> a;
1077 };
1078 #else
1079 template <class A>
1080 class WrapperS{};
1081 S<int> s;
1082 #endif
1083 
1084 #if defined(FIRST)
1085 template <class A>
1086 class WrapperT;
1087 template <class A>
1088 struct T {
1089   WrapperT<A> a;
1090 
1091   public:
1092 };
1093 #elif defined(SECOND)
1094 template <class A>
1095 class WrapperT;
1096 template <class A>
1097 struct T {
1098   WrapperT<A> a;
1099 
1100   private:
1101 };
1102 #else
1103 template <class A>
1104 class WrapperT{};
1105 T<int> t;
1106 // [email protected]:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1107 // [email protected]:* {{but in 'FirstModule' found public access specifier}}
1108 #endif
1109 }  // namespace TemplateClassWithTemplateField
1110 
1111 namespace EnumWithForwardDeclaration {
1112 #if defined(FIRST)
1113 enum E : int;
1114 struct S {
1115   void get(E) {}
1116 };
1117 #elif defined(SECOND)
1118 enum E : int { A, B };
1119 struct S {
1120   void get(E) {}
1121 };
1122 #else
1123 S s;
1124 #endif
1125 
1126 #if defined(FIRST)
1127 struct T {
1128   void get(E) {}
1129   public:
1130 };
1131 #elif defined(SECOND)
1132 struct T {
1133   void get(E) {}
1134   private:
1135 };
1136 #else
1137 T t;
1138 // [email protected]:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1139 // [email protected]:* {{but in 'FirstModule' found public access specifier}}
1140 #endif
1141 }  // namespace EnumWithForwardDeclaration
1142 
1143 namespace StructWithForwardDeclaration {
1144 #if defined(FIRST)
1145 struct P {};
1146 struct S {
1147   struct P *ptr;
1148 };
1149 #elif defined(SECOND)
1150 struct S {
1151   struct P *ptr;
1152 };
1153 #else
1154 S s;
1155 #endif
1156 
1157 #if defined(FIRST)
1158 struct Q {};
1159 struct T {
1160   struct Q *ptr;
1161   public:
1162 };
1163 #elif defined(SECOND)
1164 struct T {
1165   struct Q *ptr;
1166   private:
1167 };
1168 #else
1169 T t;
1170 // [email protected]:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1171 // [email protected]:* {{but in 'FirstModule' found public access specifier}}
1172 #endif
1173 }  // namespace StructWithForwardDeclaration
1174 
1175 namespace StructWithForwardDeclarationNoDefinition {
1176 #if defined(FIRST)
1177 struct P;
1178 struct S {
1179   struct P *ptr;
1180 };
1181 #elif defined(SECOND)
1182 struct S {
1183   struct P *ptr;
1184 };
1185 #else
1186 S s;
1187 #endif
1188 
1189 #if defined(FIRST)
1190 struct Q;
1191 struct T {
1192   struct Q *ptr;
1193 
1194   public:
1195 };
1196 #elif defined(SECOND)
1197 struct T {
1198   struct Q *ptr;
1199 
1200   private:
1201 };
1202 #else
1203 T t;
1204 // [email protected]:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
1205 // [email protected]:* {{but in 'FirstModule' found public access specifier}}
1206 #endif
1207 }  // namespace StructWithForwardDeclarationNoDefinition
1208 
1209 namespace LateParsedDefaultArgument {
1210 #if defined(FIRST)
1211 template <typename T>
1212 struct S {
1213   struct R {
1214     void foo(T x = 0) {}
1215   };
1216 };
1217 #elif defined(SECOND)
1218 #else
1219 void run() {
1220   S<int>::R().foo();
1221 }
1222 #endif
1223 }
1224 
1225 namespace LateParsedDefaultArgument {
1226 #if defined(FIRST)
1227 template <typename alpha> struct Bravo {
1228   void charlie(bool delta = false) {}
1229 };
1230 typedef Bravo<char> echo;
1231 echo foxtrot;
1232 
1233 Bravo<char> golf;
1234 #elif defined(SECOND)
1235 #else
1236 #endif
1237 }
1238 
1239 namespace DifferentParameterNameInTemplate {
1240 #if defined(FIRST) || defined(SECOND)
1241 template <typename T>
1242 struct S {
1243   typedef T Type;
1244 
1245   static void Run(const Type *name_one);
1246 };
1247 
1248 template <typename T>
1249 void S<T>::Run(const T *name_two) {}
1250 
1251 template <typename T>
1252 struct Foo {
1253   ~Foo() { Handler::Run(nullptr); }
1254   Foo() {}
1255 
1256   class Handler : public S<T> {};
1257 
1258   void Get(typename Handler::Type *x = nullptr) {}
1259   void Add() { Handler::Run(nullptr); }
1260 };
1261 #endif
1262 
1263 #if defined(FIRST)
1264 struct Beta;
1265 
1266 struct Alpha {
1267   Alpha();
1268   void Go() { betas.Get(); }
1269   Foo<Beta> betas;
1270 };
1271 
1272 #elif defined(SECOND)
1273 struct Beta {};
1274 
1275 struct BetaHelper {
1276   void add_Beta() { betas.Add(); }
1277   Foo<Beta> betas;
1278 };
1279 
1280 #else
1281 Alpha::Alpha() {}
1282 #endif
1283 }
1284 
1285 namespace ParameterTest {
1286 #if defined(FIRST)
1287 class X {};
1288 template <typename G>
1289 class S {
1290   public:
1291    typedef G Type;
1292    static inline G *Foo(const G *a, int * = nullptr);
1293 };
1294 
1295 template<typename G>
1296 G* S<G>::Foo(const G* aaaa, int*) {}
1297 #elif defined(SECOND)
1298 template <typename G>
1299 class S {
1300   public:
1301    typedef G Type;
1302    static inline G *Foo(const G *a, int * = nullptr);
1303 };
1304 
1305 template<typename G>
1306 G* S<G>::Foo(const G* asdf, int*) {}
1307 #else
1308 S<X> s;
1309 #endif
1310 }
1311 
1312 namespace MultipleTypedefs {
1313 #if defined(FIRST)
1314 typedef int B1;
1315 typedef B1 A1;
1316 struct S1 {
1317   A1 x;
1318 };
1319 #elif defined(SECOND)
1320 typedef int A1;
1321 struct S1 {
1322   A1 x;
1323 };
1324 #else
1325 S1 s1;
1326 #endif
1327 
1328 #if defined(FIRST)
1329 struct T2 { int x; };
1330 typedef T2 B2;
1331 typedef B2 A2;
1332 struct S2 {
1333   T2 x;
1334 };
1335 #elif defined(SECOND)
1336 struct T2 { int x; };
1337 typedef T2 A2;
1338 struct S2 {
1339   T2 x;
1340 };
1341 #else
1342 S2 s2;
1343 #endif
1344 }
1345 
1346 // Keep macros contained to one file.
1347 #ifdef FIRST
1348 #undef FIRST
1349 #endif
1350 #ifdef SECOND
1351 #undef SECOND
1352 #endif
1353