summaryrefslogtreecommitdiffstats
path: root/test/Modules/odr_hash.cpp
blob: 60e39cf9d4eda1f5bfb07969f9f2fa6fb0f0632b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
// Clear and create directories
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: mkdir %t/cache
// RUN: mkdir %t/Inputs

// Build first header file
// RUN: echo "#define FIRST" >> %t/Inputs/first.h
// RUN: cat %s               >> %t/Inputs/first.h

// Build second header file
// RUN: echo "#define SECOND" >> %t/Inputs/second.h
// RUN: cat %s                >> %t/Inputs/second.h

// Build module map file
// RUN: echo "module first {"           >> %t/Inputs/module.map
// RUN: echo "    header \"first.h\""   >> %t/Inputs/module.map
// RUN: echo "}"                        >> %t/Inputs/module.map
// RUN: echo "module second {"          >> %t/Inputs/module.map
// RUN: echo "    header \"second.h\""  >> %t/Inputs/module.map
// RUN: echo "}"                        >> %t/Inputs/module.map

// Run test
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++11

#if !defined(FIRST) && !defined(SECOND)
#include "first.h"
#include "second.h"
#endif

#if defined(FIRST)
struct S1 {
  public:
};
#elif defined(SECOND)
struct S1 {
  private:
};
#else
S1 s1;
// expected-error@first.h:* {{'S1' has different definitions in different modules; first difference is definition in module 'first' found public access specifier}}
// expected-note@second.h:* {{but in 'second' found private access specifier}}
#endif

#if defined(FIRST)
struct S2Friend2 {};
struct S2 {
  friend S2Friend2;
};
#elif defined(SECOND)
struct S2Friend1 {};
struct S2 {
  friend S2Friend1;
};
#else
S2 s2;
// expected-error@first.h:* {{'S2' has different definitions in different modules; first difference is definition in module 'first' found friend 'S2Friend2'}}
// expected-note@second.h:* {{but in 'second' found other friend 'S2Friend1'}}
#endif

#if defined(FIRST)
template<class>
struct S3Template {};
struct S3 {
  friend S3Template<int>;
};
#elif defined(SECOND)
template<class>
struct S3Template {};
struct S3 {
  friend S3Template<double>;
};
#else
S3 s3;
// expected-error@first.h:* {{'S3' has different definitions in different modules; first difference is definition in module 'first' found friend 'S3Template<int>'}}
// expected-note@second.h:* {{but in 'second' found other friend 'S3Template<double>'}}
#endif

#if defined(FIRST)
struct S4 {
  static_assert(1 == 1, "First");
};
#elif defined(SECOND)
struct S4 {
  static_assert(1 == 1, "Second");
};
#else
S4 s4;
// expected-error@first.h:* {{'S4' has different definitions in different modules; first difference is definition in module 'first' found static assert with message}}
// expected-note@second.h:* {{but in 'second' found static assert with different message}}
#endif

#if defined(FIRST)
struct S5 {
  static_assert(1 == 1, "Message");
};
#elif defined(SECOND)
struct S5 {
  static_assert(2 == 2, "Message");
};
#else
S5 s5;
// expected-error@first.h:* {{'S5' has different definitions in different modules; first difference is definition in module 'first' found static assert with condition}}
// expected-note@second.h:* {{but in 'second' found static assert with different condition}}
#endif

#if defined(FIRST)
struct S6 {
  int First();
};
#elif defined(SECOND)
struct S6 {
  int Second();
};
#else
S6 s6;
// expected-error@second.h:* {{'S6::Second' from module 'second' is not present in definition of 'S6' in module 'first'}}
// expected-note@first.h:* {{definition has no member 'Second'}}
#endif

#if defined(FIRST)
struct S7 {
  double foo();
};
#elif defined(SECOND)
struct S7 {
  int foo();
};
#else
S7 s7;
// expected-error@second.h:* {{'S7::foo' from module 'second' is not present in definition of 'S7' in module 'first'}}
// expected-note@first.h:* {{declaration of 'foo' does not match}}
#endif

#if defined(FIRST)
struct S8 {
  void foo();
};
#elif defined(SECOND)
struct S8 {
  void foo() {}
};
#else
S8 s8;
// expected-error@first.h:* {{'S8' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S9 {
  void foo() { int y = 5; }
};
#elif defined(SECOND)
struct S9 {
  void foo() { int x = 5; }
};
#else
S9 s9;
// expected-error@first.h:* {{'S9' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S10 {
  struct {
    int x;
  } a;
};
#elif defined(SECOND)
struct S10 {
  struct {
    int x;
    int y;
  } a;
};
#else
S10 s10;
// expected-error-re@second.h:* {{'S10::(anonymous struct)::y' from module 'second' is not present in definition of 'S10::(anonymous struct at {{.*}}first.h:{{[0-9]*}}:{{[0-9]*}})' in module 'first'}}
// expected-note@first.h:* {{definition has no member 'y'}}

// expected-error@first.h:* {{'S10' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S11 {
  void foo() { int y = sizeof(int); }
};
#elif defined(SECOND)
struct S11 {
  void foo() { int y = sizeof(double); }
};
#else
S11 s11;
// expected-error@first.h:* {{'S11' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S12 {
  int x = sizeof(x);
  int y = sizeof(x);
};
#elif defined(SECOND)
struct S12 {
  int x = sizeof(x);
  int y = sizeof(y);
};
#else
S12 s12;
// expected-error@first.h:* {{'S12' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S13 {
  template <typename A> void foo();
};
#elif defined(SECOND)
struct S13 {
  template <typename B> void foo();
};
#else
S13 s13;
// expected-error@first.h:* {{'S13' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S14 {
  template <typename A, typename B> void foo();
};
#elif defined(SECOND)
struct S14 {
  template <typename A> void foo();
};
#else
S14 s14;
// expected-error@second.h:* {{'S14::foo' from module 'second' is not present in definition of 'S14' in module 'first'}}
// expected-note@first.h:* {{declaration of 'foo' does not match}}
#endif

#if defined(FIRST)
template <typename T>
struct S15 : T {
  void foo() {
    int x = __builtin_offsetof(T, first);
  }
};
#elif defined(SECOND)
template <typename T>
struct S15 : T {
  void foo() {
    int x = __builtin_offsetof(T, second);
  }
};
#else
template <typename T>
void Test15() {
  S15<T> s15;
// expected-error@first.h:* {{'S15' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
}
#endif

#if defined(FIRST)
struct S16 {
  template <template<int = 0> class Y>
  void foo() {
    Y<> y;
  }
};
#elif defined(SECOND)
struct S16 {
  template <template<int = 1> class Y>
  void foo() {
    Y<> y;
  }
};
#else
void TestS16() {
  S16 s16;
}
// TODO: Error here
// expected-err or@first.h:* {{'S16' has different definitions in different modules; definition in module 'first' is here}}
// expected-no te@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S17 {
  template <template <typename> class T>
  static int foo(int a = 1);
  template <template <typename> class T, template <typename> class U>
  using Q_type = T<int>;
};
#elif defined(SECOND)
struct S17 {
  template <template <typename> class T>
  static int foo(int a = 1);
  template <template <typename> class T, template <typename> class U>
  using Q_type = U<int>;
};
#else
S17 s17;
// expected-error@second.h:* {{'S17::Q_type' from module 'second' is not present in definition of 'S17' in module 'first'}}
// expected-note@first.h:* {{declaration of 'Q_type' does not match}}
#endif

#if defined(FIRST)
struct S18 {
  enum E { X1 };
};
#elif defined(SECOND)
struct S18 {
  enum X { X1 };
};
#else
S18 s18;
// expected-error@second.h:* {{'S18::X' from module 'second' is not present in definition of 'S18' in module 'first'}}
// expected-note@first.h:* {{definition has no member 'X'}}
#endif

#if defined(FIRST)
struct S19 {
  enum E { X1 };
};
#elif defined(SECOND)
struct S19 {
  enum E { X1, X2 };
};
#else
S19 s19;
// expected-error@first.h:* {{'S19' has different definitions in different modules; first difference is definition in module 'first' found enum 'E' has 1 element}}
// expected-note@second.h:* {{but in 'second' found enum 'E' has 2 elements}}
// expected-error@second.h:* {{'S19::E::X2' from module 'second' is not present in definition of 'S19::E' in module 'first'}}
// expected-note@first.h:* {{definition has no member 'X2'}}
#endif

#if defined(FIRST)
struct S20 {
  enum E { X1 = 1 };
};
#elif defined(SECOND)
struct S20 {
  enum E { X1 = 5};
};
#else
S20 s20;
// expected-error@first.h:* {{'S20' has different definitions in different modules; first difference is definition in module 'first' found element 'X1' in enum 'E' with initializer}}
// expected-note@second.h:* {{but in 'second' found element 'X1' in enum 'E' with different initializer}}
#endif

#if defined(FIRST)
struct S21 {
  void foo() {
    label:
    ;
  }
};
#elif defined(SECOND)
struct S21 {
  void foo() {
    ;
  }
};
#else
S21 s21;
// expected-error@first.h:* {{'S21' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S22 {
  void foo() {
    label_first:
    ;
  }
};
#elif defined(SECOND)
struct S22 {
  void foo() {
    label_second:
    ;
  }
};
#else
S22 s22;
// expected-error@first.h:* {{'S22' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S23 {
  typedef int a;
  typedef char b;
};
#elif defined(SECOND)
struct S23 {
  typedef char a;
  typedef int b;
};
#else
S23 s23;
// expected-error@second.h:* {{'S23::a' from module 'second' is not present in definition of 'S23' in module 'first'}}
// expected-note@first.h:* {{declaration of 'a' does not match}}
// expected-error@second.h:* {{'S23::b' from module 'second' is not present in definition of 'S23' in module 'first'}}
// expected-note@first.h:* {{declaration of 'b' does not match}}
#endif

#if defined(FIRST)
struct S24 {
  inline int foo();
};
#elif defined(SECOND)
struct S24 {
  int foo();
};
#else
S24 s24;
// expected-error@first.h:* {{'S24' has different definitions in different modules; first difference is definition in module 'first' found method 'foo' is inline}}
// expected-note@second.h:* {{but in 'second' found method 'foo' is not inline}}
#endif

#if defined(FIRST)
struct S25 {
  int x;
  S25() : x(5) {}
};
#elif defined(SECOND)
struct S25 {
  int x;
  S25() {}
};
#else
S25 s25;
// expected-error@first.h:* {{'S25' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S26 {
  int x;
  S26() : x(5) {}
};
#elif defined(SECOND)
struct S26 {
  int x;
  S26() : x(2) {}
};
#else
S26 s26;
// expected-error@first.h:* {{'S26' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S27 {
  explicit S27(int) {}
  S27() {}
};
#elif defined(SECOND)
struct S27 {
  S27(int) {}
  S27() {}
};
#else
S27 s27;
// expected-error@first.h:* {{'S27' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST) || defined(SECOND)
struct Base1 {
  Base1();
  Base1(int);
  Base1(double);
};

struct Base2 {
  Base2();
  Base2(int);
  Base2(double);
};
#endif

#if defined(FIRST)
struct S28 : public Base1 {};
#elif defined(SECOND)
struct S28 : public Base2 {};
#else
S28 s28;
// expected-error@first.h:* {{'S28' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S29 : virtual Base1 {};
#elif defined(SECOND)
struct S29 : virtual Base2 {};
#else
S29 s29;
// expected-error@first.h:* {{'S29' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S30 : public Base1 {
  S30() : Base1(1) {}
};
#elif defined(SECOND)
struct S30 : public Base1 {
  S30() : Base1(1.0) {}
};
#else
S30 s30;
// expected-error@first.h:* {{'S30' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S31 : virtual Base1 {
  S31() : Base1(1) {}
};
#elif defined(SECOND)
struct S31 : virtual Base1 {
  S31() : Base1(1.0) {}
};
#else
S31 s31;
// expected-error@first.h:* {{'S31' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S32 : public Base1, Base2 {
  S32() : Base1(1), Base2(1.0) {}
};
#elif defined(SECOND)
struct S32 : public Base2, Base1 {
  S32() : Base2(1), Base1(1.0) {}
};
#else
S32 s32;
// expected-error@first.h:* {{'S32' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S33 {
  S33() : S33(5) {}
  S33(int) {int a;}
};
#elif defined(SECOND)
struct S33 {
  S33() : S33(5) {}
  S33(int) {}
};
#else
S33 s33;
// expected-error@first.h:* {{'S33' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S34 {
  operator bool();
};
#elif defined(SECOND)
struct S34 {
  operator int();
};
#else
S34 s34;
// expected-error@second.h:* {{'S34::operator int' from module 'second' is not present in definition of 'S34' in module 'first'}}
// expected-note@first.h:* {{definition has no member 'operator int'}}
#endif

#if defined(FIRST)
struct S35 {
  explicit operator bool();
};
#elif defined(SECOND)
struct S35 {
  operator bool();
};
#else
S35 s35;
// expected-error@first.h:* {{'S35' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S36 {
  int x : 3;
};
#elif defined(SECOND)
struct S36 {
  int x : 4;
};
#else
S36 s36;
// expected-error@first.h:* {{'S36' has different definitions in different modules; first difference is definition in module 'first' found bitfield 'x'}}
// expected-note@second.h:* {{but in 'second' found bitfield 'x'}}
#endif

#if defined(FIRST)
struct S37 {
  mutable int x;
  int y;
};
#elif defined(SECOND)
struct S37 {
  int x;
  mutable int y;
};
#else
S37 s37;
// expected-error@first.h:* {{'S37' has different definitions in different modules; first difference is definition in module 'first' found mutable 'x'}}
// expected-note@second.h:* {{but in 'second' found non-mutable 'x'}}
#endif

#if defined(FIRST)
template <class X>
struct S38 { };
#elif defined(SECOND)
template <class Y>
struct S38 { };
#else
S38<int> s38;
// expected-error@first.h:* {{'S38' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
template <class X = int>
struct S39 { X x; };
#elif defined(SECOND)
template <class X = double>
struct S39 { X x; };
#else
S39<> s39;
// expected-error@first.h:* {{'S39' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
template <int X = 5>
struct S40 { int x = X; };
#elif defined(SECOND)
template <int X = 7>
struct S40 { int x = X; };
#else
S40<> s40;
// expected-error@first.h:* {{'S40' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}

#endif

#if defined(FIRST)
template <int> class T41a{};
template <template<int> class T = T41a>
struct S41 {};
#elif defined(SECOND)
template <int> class T41b{};
template <template<int> class T = T41b>
struct S41 {};
#else
using ::S41;
// expected-error@first.h:* {{'S41' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
struct S42 {
  void foo() const {}
  void bar() {}
};
#elif defined(SECOND)
struct S42 {
  void foo() {}
  void bar() const {}
};
#else
S42 s42;
// expected-error@second.h:* {{'S42::bar' from module 'second' is not present in definition of 'S42' in module 'first'}}
// expected-note@first.h:* {{declaration of 'bar' does not match}}
// expected-error@second.h:* {{'S42::foo' from module 'second' is not present in definition of 'S42' in module 'first'}}
// expected-note@first.h:* {{declaration of 'foo' does not match}}
#endif

#if defined(FIRST)
struct S43 {
  static constexpr int x = 1;
  int y = 1;
};
#elif defined(SECOND)
struct S43 {
  int x = 1;
  static constexpr int y = 1;
};
#else
S43 s43;
// expected-error@second.h:* {{'S43::x' from module 'second' is not present in definition of 'S43' in module 'first'}}
// expected-note@first.h:* {{declaration of 'x' does not match}}
// expected-error@second.h:* {{'S43::y' from module 'second' is not present in definition of 'S43' in module 'first'}}
// expected-note@first.h:* {{declaration of 'y' does not match}}
//#endif
#endif

#if defined(FIRST)
void f44();
struct S44 {
  friend void f44();
};
#elif defined(SECOND)
void g44();
struct S44 {
  friend void g44();
};
#else
S44 s44;
// expected-error@first.h:* {{'S44' has different definitions in different modules; first difference is definition in module 'first' found friend 'f44'}}
// expected-note@second.h:* {{but in 'second' found other friend 'g44'}}
#endif

#if defined(FIRST)
struct S45 { int n : 1; };
#elif defined(SECOND)
struct S45 { int n = 1; };
#else
S45 s45;
// expected-error@first.h:* {{'S45' has different definitions in different modules; first difference is definition in module 'first' found bitfield 'n'}}
// expected-note@second.h:* {{but in 'second' found field 'n'}}
#endif

#if defined(FIRST)
struct S46 {
  int operator+(int) { return 0; }
};
#elif defined(SECOND)
struct S46 {
  int operator-(int) { return 0; }
};
#else
S46 s46;
// expected-error@second.h:* {{'S46::operator-' from module 'second' is not present in definition of 'S46' in module 'first'}}
// expected-note@first.h:* {{definition has no member 'operator-'}}
#endif

#if defined(FIRST)
template <typename T>
struct S47 {
  int foo(int);
  float foo(float);
  int bar(int);
  float bar(float);
  int x = foo(T());
};
#elif defined(SECOND)
template <typename T>
struct S47 {
  int foo(int);
  float foo(float);
  int bar(int);
  float bar(float);
  int x = bar(T());
};
#else
template <typename T>
using S48 = S47<T>;
// expected-error@first.h:* {{'S47' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
template <typename T>
struct S49 {
  int operator+(int);
  float operator+(float);
  int operator-(int);
  float operator-(float);
  int x = S49() + T();
};
#elif defined(SECOND)
template <typename T>
struct S49 {
  int operator+(int);
  float operator+(float);
  int operator-(int);
  float operator-(float);
  int x = S49() - T();
};
#else
template <typename T>
using S50 = S49<T>;
// expected-error@first.h:* {{'S49' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
namespace A51 {
  void foo();
}
struct S51 {
  S51() {
    A51::foo();
  }
};
#elif defined(SECOND)
namespace B51 {
  void foo();
}
struct S51 {
  S51() {
    B51::foo();
  }
};
#else
S51 s51;
// expected-error@first.h:* {{'S51' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
namespace N52 {
  void foo();
}
struct S52 {
  S52() {
    N52::foo();
  }
};
#elif defined(SECOND)
namespace N52 {
  void foo();
}
struct S52 {
  S52() {
    ::N52::foo();
  }
};
#else
S52 s52;
// expected-error@first.h:* {{'S52' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
namespace N53 {
  struct foo {
    static int bar();
  };
  using A = foo;
}
struct S53 {
  S53() {
    N53::A::bar();
  }
};
#elif defined(SECOND)
namespace N53 {
  struct foo {
    static int bar();
  };
  using B = foo;
}
struct S53 {
  S53() {
    N53::B::bar();
  }
};
#else
S53 s53;
// expected-error@first.h:* {{'S53' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
namespace N54 {
namespace A {
void foo();
}
namespace AA = A;
}

struct S54 {
  S54() {
    N54::AA::foo();
  }
};
#elif defined(SECOND)
namespace N54 {
namespace B {
void foo();
}
namespace BB = B;
}

struct S54 {
  S54() {
    N54::BB::foo();
  }
};
#else
S54 s54;
// expected-error@first.h:* {{'S54' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
namespace N55 {
namespace A {
void foo();
}
namespace X = A;
}

struct S55 {
  S55() {
    N55::X::foo();
  }
};
#elif defined(SECOND)
namespace N55 {
namespace B {
void foo();
}
namespace X = B;
}

struct S55 {
  S55() {
    N55::X::foo();
  }
};
#else
S55 s55;
// expected-error@first.h:* {{'S55' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif

#if defined(FIRST)
template<int> struct foo56{};
template <template<int> class T>
struct S56 {};
struct S57 {
  S56<foo56> a;
};
#elif defined(SECOND)
template<int> struct bar56{};
template <template<int> class T>
struct S56 {};
struct S57 {
  S56<bar56> a;
};
#else
S57 s57;
// expected-error@second.h:* {{'S57::a' from module 'second' is not present in definition of 'S57' in module 'first'}}
// expected-note@first.h:* {{declaration of 'a' does not match}}
#endif

#if defined(FIRST)
template<int> struct foo58{};
template <template<int> class T>
struct S58 {};
struct S59 {
  S58<foo58> a;
};
#elif defined(SECOND)
template<int> struct foo58{};
template <template<int> class T>
struct S58 {};
struct S59 {
  S58<::foo58> a;
};
#else
S59 s59;
// expected-error@first.h:* {{'S59' has different definitions in different modules; definition in module 'first' is here}}
// expected-note@second.h:* {{definition in module 'second' is here}}
#endif


#if defined(FIRST)
struct S60a {};

typedef S60a S61;

struct S62 {
  S61 s61;
};
#elif defined(SECOND)
struct S60b {};

typedef S60b S61;

struct S62 {
  S61 s61;
};
#else
S62 s62;
// expected-error@second.h:* {{'S62::s61' from module 'second' is not present in definition of 'S62' in module 'first'}}
// expected-note@first.h:* {{declaration of 's61' does not match}}
#endif

// Don't warn on these cases
#if defined(FIRST)
void f01(int = 0);
struct S01 { friend void f01(int); };
#elif defined(SECOND)
void f01(int);
struct S01 { friend void f01(int); };
#else
S01 s01;
#endif

#if defined(FIRST)
template <template <int> class T> class Wrapper {};

template <int N> class SelfReference {
  SelfReference(Wrapper<::SelfReference> &R) {}
};

struct Xx {
  struct Yy {
  };
};

Xx::Xx::Xx::Yy yy;

namespace NNS {
template <typename> struct Foo;
template <template <class> class T = NNS::Foo>
struct NestedNamespaceSpecifier {};
}
#endif

#if defined(FIRST)
struct S02 { };
void S02Construct() {
  S02 foo;
  S02 bar = foo;
  S02 baz(bar);
}
#elif defined(SECOND)
struct S02 { };
#else
S02 s02;
#endif

#if defined(FIRST)
template <class>
struct S03 {};
#elif defined(SECOND)
template <class>
struct S03 {};
#else
S03<int> s03;
#endif

#if defined(FIRST)
template <class T>
struct S04 {
  T t;
};
#elif defined(SECOND)
template <class T>
struct S04 {
  T t;
};
#else
S03<int> s04;
#endif

#if defined(FIRST)
template <class T>
class Wrapper05;
template <class T>
struct S05 {
  Wrapper05<T> t;
};
#elif defined(SECOND)
template <class T>
class Wrapper05;
template <class T>
struct S05 {
  Wrapper05<T> t;
};
#else
template <class T>
class Wrapper05{};
S05<int> s05;
#endif

#if defined(FIRST)
enum E06 : int;
struct S06 {
  void get(E06) {}
};
#elif defined(SECOND)
enum E06 : int { A06 };
struct S06 {
  void get(E06) {}
};
#else
S06 s06;
#endif

#if defined(FIRST)
struct S07a {};
struct S07 {
  struct S07a *ptr;
};
#elif defined(SECOND)
struct S07 {
  struct S07a *ptr;
};
#else
S07 s07;
#endif

#if defined(FIRST)
struct S08a;
struct S08 {
  struct S08a *ptr;
};
#elif defined(SECOND)
struct S08 {
  struct S08a *ptr;
};
#else
S08 s08;
#endif

// TODO: Error on these cases.
#if defined(FIRST)
enum E { E1 };
#elif defined(SECOND)
enum E { E1, E2 };
#else
E e;
#endif

#if defined(FIRST)
int foo() { return 1; }
#elif defined(SECOND)
int foo() { return 2; }
#else
int number = foo();
#endif

// Keep macros contained to one file.
#ifdef FIRST
#undef FIRST
#endif
#ifdef SECOND
#undef SECOND
#endif