blob: 00730a0e579cc42f1fd05dbd541155a84bb4e127 [file] [log] [blame]
Richard Trieue7f7ed22017-02-22 01:11:25 +00001// Clear and create directories
2// RUN: rm -rf %t
3// RUN: mkdir %t
4// RUN: mkdir %t/cache
5// RUN: mkdir %t/Inputs
6
7// Build first header file
8// RUN: echo "#define FIRST" >> %t/Inputs/first.h
9// RUN: cat %s >> %t/Inputs/first.h
10
11// Build second header file
12// RUN: echo "#define SECOND" >> %t/Inputs/second.h
13// RUN: cat %s >> %t/Inputs/second.h
14
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
Richard Trieu639d7b62017-02-22 22:22:42 +000024// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x c++ -I%t/Inputs -verify %s -std=c++1z
Richard Trieue7f7ed22017-02-22 01:11:25 +000025
26#if !defined(FIRST) && !defined(SECOND)
27#include "first.h"
28#include "second.h"
29#endif
30
31namespace AccessSpecifiers {
32#if defined(FIRST)
33struct S1 {
34};
35#elif defined(SECOND)
36struct S1 {
37 private:
38};
39#else
40S1 s1;
41// expected-error@second.h:* {{'AccessSpecifiers::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
42// expected-note@first.h:* {{but in 'FirstModule' found end of class}}
43#endif
44
45#if defined(FIRST)
46struct S2 {
47 public:
48};
49#elif defined(SECOND)
50struct S2 {
51 protected:
52};
53#else
54S2 s2;
55// expected-error@second.h:* {{'AccessSpecifiers::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found protected access specifier}}
56// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
57#endif
58} // namespace AccessSpecifiers
59
Richard Trieu639d7b62017-02-22 22:22:42 +000060namespace StaticAssert {
61#if defined(FIRST)
62struct S1 {
63 static_assert(1 == 1, "First");
64};
65#elif defined(SECOND)
66struct S1 {
67 static_assert(1 == 1, "Second");
68};
69#else
70S1 s1;
71// expected-error@second.h:* {{'StaticAssert::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with message}}
72// expected-note@first.h:* {{but in 'FirstModule' found static assert with different message}}
73#endif
74
75#if defined(FIRST)
76struct S2 {
77 static_assert(2 == 2, "Message");
78};
79#elif defined(SECOND)
80struct S2 {
81 static_assert(2 == 2);
82};
83#else
84S2 s2;
85// 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}}
86// expected-note@first.h:* {{but in 'FirstModule' found static assert with message}}
87#endif
88
89#if defined(FIRST)
90struct S3 {
91 static_assert(3 == 3, "Message");
92};
93#elif defined(SECOND)
94struct S3 {
95 static_assert(3 != 4, "Message");
96};
97#else
98S3 s3;
99// expected-error@second.h:* {{'StaticAssert::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found static assert with condition}}
100// expected-note@first.h:* {{but in 'FirstModule' found static assert with different condition}}
101#endif
102
103#if defined(FIRST)
104struct S4 {
105 static_assert(4 == 4, "Message");
106};
107#elif defined(SECOND)
108struct S4 {
109 public:
110};
111#else
112S4 s4;
113// expected-error@second.h:* {{'StaticAssert::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
114// expected-note@first.h:* {{but in 'FirstModule' found static assert}}
115#endif
116}
117
Richard Trieud0786092017-02-23 00:23:01 +0000118namespace Field {
119#if defined(FIRST)
120struct S1 {
121 int x;
122 private:
123 int y;
124};
125#elif defined(SECOND)
126struct S1 {
127 int x;
128 int y;
129};
130#else
131S1 s1;
132// expected-error@second.h:* {{'Field::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found field}}
133// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
134#endif
135
136#if defined(FIRST)
137struct S2 {
138 int x;
139 int y;
140};
141#elif defined(SECOND)
142struct S2 {
143 int y;
144 int x;
145};
146#else
147S2 s2;
148// expected-error@second.h:* {{'Field::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'y'}}
149// expected-note@first.h:* {{but in 'FirstModule' found field 'x'}}
150#endif
Richard Trieubcaaf962017-02-23 03:25:57 +0000151
152#if defined(FIRST)
153struct S3 {
154 double x;
155};
156#elif defined(SECOND)
157struct S3 {
158 int x;
159};
160#else
161S3 s3;
162// expected-error@first.h:* {{'Field::S3::x' from module 'FirstModule' is not present in definition of 'Field::S3' in module 'SecondModule'}}
163// expected-note@second.h:* {{declaration of 'x' does not match}}
164#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000165
166#if defined(FIRST)
167typedef int A;
168struct S4 {
169 A x;
170};
171
172struct S5 {
173 A x;
174};
175#elif defined(SECOND)
176typedef int B;
177struct S4 {
178 B x;
179};
180
181struct S5 {
182 int x;
183};
184#else
185S4 s4;
186// expected-error@second.h:* {{'Field::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'B' (aka 'int')}}
187// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}}
188
189S5 s5;
190// 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'}}
191// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with type 'A' (aka 'int')}}
192#endif
193
Richard Trieu93772fc2017-02-24 20:59:28 +0000194#if defined(FIRST)
195struct S6 {
196 unsigned x;
197};
198#elif defined(SECOND)
199struct S6 {
200 unsigned x : 1;
201};
202#else
203S6 s6;
204// expected-error@second.h:* {{'Field::S6' has different definitions in different modules; first difference is definition in module 'SecondModule' found bitfield 'x'}}
205// expected-note@first.h:* {{but in 'FirstModule' found non-bitfield 'x'}}
206#endif
207
208#if defined(FIRST)
209struct S7 {
210 unsigned x : 2;
211};
212#elif defined(SECOND)
213struct S7 {
214 unsigned x : 1;
215};
216#else
217S7 s7;
218// 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}}
219// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
220#endif
221
222#if defined(FIRST)
223struct S8 {
224 unsigned x : 2;
225};
226#elif defined(SECOND)
227struct S8 {
228 unsigned x : 1 + 1;
229};
230#else
231S8 s8;
232// 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}}
233// expected-note@first.h:* {{but in 'FirstModule' found bitfield 'x' with different width expression}}
234#endif
Richard Trieu8459ddf2017-02-24 02:59:12 +0000235
Richard Trieu8d543e22017-02-24 23:35:37 +0000236#if defined(FIRST)
237struct S9 {
238 mutable int x;
239};
240#elif defined(SECOND)
241struct S9 {
242 int x;
243};
244#else
245S9 s9;
246// expected-error@second.h:* {{'Field::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found non-mutable field 'x'}}
247// expected-note@first.h:* {{but in 'FirstModule' found mutable field 'x'}}
248#endif
249
250#if defined(FIRST)
251struct S10 {
252 unsigned x = 5;
253};
254#elif defined(SECOND)
255struct S10 {
256 unsigned x;
257};
258#else
259S10 s10;
260// 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}}
261// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with an initializer}}
262#endif
263
264#if defined(FIRST)
265struct S11 {
266 unsigned x = 5;
267};
268#elif defined(SECOND)
269struct S11 {
270 unsigned x = 7;
271};
272#else
273S11 s11;
274// 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}}
275// expected-note@first.h:* {{but in 'FirstModule' found field 'x' with a different initializer}}
276#endif
277
Richard Trieud0786092017-02-23 00:23:01 +0000278} // namespace Field
279
Richard Trieu48143742017-02-28 21:24:38 +0000280namespace Method {
281#if defined(FIRST)
282struct S1 {
283 void A() {}
284};
285#elif defined(SECOND)
286struct S1 {
287 private:
288 void A() {}
289};
290#else
291S1 s1;
292// expected-error@second.h:* {{'Method::S1' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
293// expected-note@first.h:* {{but in 'FirstModule' found method}}
294#endif
295
296#if defined(FIRST)
297struct S2 {
298 void A() {}
299 void B() {}
300};
301#elif defined(SECOND)
302struct S2 {
303 void B() {}
304 void A() {}
305};
306#else
307S2 s2;
308// expected-error@second.h:* {{'Method::S2' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'B'}}
309// expected-note@first.h:* {{but in 'FirstModule' found method 'A'}}
310#endif
Richard Trieu583e2c12017-03-04 00:08:58 +0000311
312#if defined(FIRST)
313struct S3 {
314 static void A() {}
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000315 void A(int) {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000316};
317#elif defined(SECOND)
318struct S3 {
Richard Trieuf4b54fe2017-03-04 03:04:15 +0000319 void A(int) {}
320 static void A() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000321};
322#else
323S3 s3;
324// 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}}
325// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is static}}
326#endif
327
328#if defined(FIRST)
329struct S4 {
330 virtual void A() {}
331 void B() {}
332};
333#elif defined(SECOND)
334struct S4 {
335 void A() {}
336 virtual void B() {}
337};
338#else
339S4 s4;
340// 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}}
341// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is virtual}}
342#endif
343
344#if defined(FIRST)
345struct S5 {
346 virtual void A() = 0;
347 virtual void B() {};
348};
349#elif defined(SECOND)
350struct S5 {
351 virtual void A() {}
352 virtual void B() = 0;
353};
354#else
355S5 *s5;
356// expected-error@second.h:* {{'Method::S5' has different definitions in different modules; first difference is definition in module 'SecondModule' found method 'A' is virtual}}
357// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is pure virtual}}
358#endif
359
360#if defined(FIRST)
361struct S6 {
362 inline void A() {}
363};
364#elif defined(SECOND)
365struct S6 {
366 void A() {}
367};
368#else
369S6 s6;
370// 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}}
371// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is inline}}
372#endif
373
374#if defined(FIRST)
375struct S7 {
376 void A() volatile {}
377 void A() {}
378};
379#elif defined(SECOND)
380struct S7 {
381 void A() {}
382 void A() volatile {}
383};
384#else
385S7 s7;
386// 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}}
387// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is volatile}}
388#endif
389
390#if defined(FIRST)
391struct S8 {
392 void A() const {}
393 void A() {}
394};
395#elif defined(SECOND)
396struct S8 {
397 void A() {}
398 void A() const {}
399};
400#else
401S8 s8;
402// 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}}
403// expected-note@first.h:* {{but in 'FirstModule' found method 'A' is const}}
404#endif
405
Richard Trieu48143742017-02-28 21:24:38 +0000406} // namespace Method
407
Richard Trieue7f7ed22017-02-22 01:11:25 +0000408// Naive parsing of AST can lead to cycles in processing. Ensure
409// self-references don't trigger an endless cycles of AST node processing.
410namespace SelfReference {
411#if defined(FIRST)
412template <template <int> class T> class Wrapper {};
413
414template <int N> class S {
415 S(Wrapper<::SelfReference::S> &Ref) {}
416};
417
418struct Xx {
419 struct Yy {
420 };
421};
422
423Xx::Xx::Xx::Yy yy;
424
425namespace NNS {
426template <typename> struct Foo;
427template <template <class> class T = NNS::Foo>
428struct NestedNamespaceSpecifier {};
429}
430#endif
431} // namespace SelfReference
432
Richard Trieu33562c22017-03-08 00:13:19 +0000433namespace TypeDef {
434#if defined(FIRST)
435struct S1 {
436 typedef int a;
437};
438#elif defined(SECOND)
439struct S1 {
440 typedef double a;
441};
442#else
443S1 s1;
444// expected-error@first.h:* {{'TypeDef::S1::a' from module 'FirstModule' is not present in definition of 'TypeDef::S1' in module 'SecondModule'}}
445// expected-note@second.h:* {{declaration of 'a' does not match}}
446#endif
447
448#if defined(FIRST)
449struct S2 {
450 typedef int a;
451};
452#elif defined(SECOND)
453struct S2 {
454 typedef int b;
455};
456#else
457S2 s2;
458// expected-error@first.h:* {{'TypeDef::S2::a' from module 'FirstModule' is not present in definition of 'TypeDef::S2' in module 'SecondModule'}}
459// expected-note@second.h:* {{definition has no member 'a'}}
460#endif
461
462#if defined(FIRST)
463typedef int T;
464struct S3 {
465 typedef T a;
466};
467#elif defined(SECOND)
468typedef double T;
469struct S3 {
470 typedef T a;
471};
472#else
473S3 s3;
474// expected-error@first.h:* {{'TypeDef::S3::a' from module 'FirstModule' is not present in definition of 'TypeDef::S3' in module 'SecondModule'}}
475// expected-note@second.h:* {{declaration of 'a' does not match}}
476#endif
477} // namespace TypeDef
478
479namespace Using {
480#if defined(FIRST)
481struct S1 {
482 using a = int;
483};
484#elif defined(SECOND)
485struct S1 {
486 using a = double;
487};
488#else
489S1 s1;
490// expected-error@first.h:* {{'Using::S1::a' from module 'FirstModule' is not present in definition of 'Using::S1' in module 'SecondModule'}}
491// expected-note@second.h:* {{declaration of 'a' does not match}}
492#endif
493
494#if defined(FIRST)
495struct S2 {
496 using a = int;
497};
498#elif defined(SECOND)
499struct S2 {
500 using b = int;
501};
502#else
503S2 s2;
504// expected-error@first.h:* {{'Using::S2::a' from module 'FirstModule' is not present in definition of 'Using::S2' in module 'SecondModule'}}
505// expected-note@second.h:* {{definition has no member 'a'}}
506#endif
507
508#if defined(FIRST)
509typedef int T;
510struct S3 {
511 using a = T;
512};
513#elif defined(SECOND)
514typedef double T;
515struct S3 {
516 using a = T;
517};
518#else
519S3 s3;
520// expected-error@first.h:* {{'Using::S3::a' from module 'FirstModule' is not present in definition of 'Using::S3' in module 'SecondModule'}}
521// expected-note@second.h:* {{declaration of 'a' does not match}}
522#endif
523} // namespace Using
524
525
Richard Trieue7f7ed22017-02-22 01:11:25 +0000526// Interesting cases that should not cause errors. struct S should not error
527// while struct T should error at the access specifier mismatch at the end.
528namespace AllDecls {
529#if defined(FIRST)
Richard Trieu8459ddf2017-02-24 02:59:12 +0000530typedef int INT;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000531struct S {
532 public:
533 private:
534 protected:
Richard Trieu639d7b62017-02-22 22:22:42 +0000535
536 static_assert(1 == 1, "Message");
537 static_assert(2 == 2);
Richard Trieud0786092017-02-23 00:23:01 +0000538
539 int x;
540 double y;
Richard Trieu8459ddf2017-02-24 02:59:12 +0000541
542 INT z;
Richard Trieu93772fc2017-02-24 20:59:28 +0000543
544 unsigned a : 1;
545 unsigned b : 2*2 + 5/2;
Richard Trieu8d543e22017-02-24 23:35:37 +0000546
547 mutable int c = sizeof(x + y);
Richard Trieu48143742017-02-28 21:24:38 +0000548
549 void method() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000550 static void static_method() {}
551 virtual void virtual_method() {}
552 virtual void pure_virtual_method() = 0;
553 inline void inline_method() {}
554 void volatile_method() volatile {}
555 void const_method() const {}
Richard Trieu33562c22017-03-08 00:13:19 +0000556
557 typedef int typedef_int;
558 using using_int = int;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000559};
560#elif defined(SECOND)
Richard Trieu8459ddf2017-02-24 02:59:12 +0000561typedef int INT;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000562struct S {
563 public:
564 private:
565 protected:
Richard Trieu639d7b62017-02-22 22:22:42 +0000566
567 static_assert(1 == 1, "Message");
568 static_assert(2 == 2);
Richard Trieud0786092017-02-23 00:23:01 +0000569
570 int x;
571 double y;
Richard Trieu8459ddf2017-02-24 02:59:12 +0000572
573 INT z;
Richard Trieu93772fc2017-02-24 20:59:28 +0000574
575 unsigned a : 1;
576 unsigned b : 2 * 2 + 5 / 2;
Richard Trieu8d543e22017-02-24 23:35:37 +0000577
578 mutable int c = sizeof(x + y);
Richard Trieu48143742017-02-28 21:24:38 +0000579
580 void method() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000581 static void static_method() {}
582 virtual void virtual_method() {}
583 virtual void pure_virtual_method() = 0;
584 inline void inline_method() {}
585 void volatile_method() volatile {}
586 void const_method() const {}
Richard Trieu33562c22017-03-08 00:13:19 +0000587
588 typedef int typedef_int;
589 using using_int = int;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000590};
591#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000592S *s;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000593#endif
594
595#if defined(FIRST)
Richard Trieu8459ddf2017-02-24 02:59:12 +0000596typedef int INT;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000597struct T {
598 public:
599 private:
600 protected:
601
Richard Trieu639d7b62017-02-22 22:22:42 +0000602 static_assert(1 == 1, "Message");
603 static_assert(2 == 2);
604
Richard Trieud0786092017-02-23 00:23:01 +0000605 int x;
606 double y;
607
Richard Trieu8459ddf2017-02-24 02:59:12 +0000608 INT z;
609
Richard Trieu93772fc2017-02-24 20:59:28 +0000610 unsigned a : 1;
611 unsigned b : 2 * 2 + 5 / 2;
612
Richard Trieu8d543e22017-02-24 23:35:37 +0000613 mutable int c = sizeof(x + y);
614
Richard Trieu48143742017-02-28 21:24:38 +0000615 void method() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000616 static void static_method() {}
617 virtual void virtual_method() {}
618 virtual void pure_virtual_method() = 0;
619 inline void inline_method() {}
620 void volatile_method() volatile {}
621 void const_method() const {}
Richard Trieu48143742017-02-28 21:24:38 +0000622
Richard Trieu33562c22017-03-08 00:13:19 +0000623 typedef int typedef_int;
624 using using_int = int;
625
Richard Trieue7f7ed22017-02-22 01:11:25 +0000626 private:
627};
628#elif defined(SECOND)
Richard Trieu8459ddf2017-02-24 02:59:12 +0000629typedef int INT;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000630struct T {
631 public:
632 private:
633 protected:
634
Richard Trieu639d7b62017-02-22 22:22:42 +0000635 static_assert(1 == 1, "Message");
636 static_assert(2 == 2);
637
Richard Trieud0786092017-02-23 00:23:01 +0000638 int x;
639 double y;
640
Richard Trieu8459ddf2017-02-24 02:59:12 +0000641 INT z;
642
Richard Trieu93772fc2017-02-24 20:59:28 +0000643 unsigned a : 1;
644 unsigned b : 2 * 2 + 5 / 2;
645
Richard Trieu8d543e22017-02-24 23:35:37 +0000646 mutable int c = sizeof(x + y);
647
Richard Trieu48143742017-02-28 21:24:38 +0000648 void method() {}
Richard Trieu583e2c12017-03-04 00:08:58 +0000649 static void static_method() {}
650 virtual void virtual_method() {}
651 virtual void pure_virtual_method() = 0;
652 inline void inline_method() {}
653 void volatile_method() volatile {}
654 void const_method() const {}
Richard Trieu48143742017-02-28 21:24:38 +0000655
Richard Trieu33562c22017-03-08 00:13:19 +0000656 typedef int typedef_int;
657 using using_int = int;
658
Richard Trieue7f7ed22017-02-22 01:11:25 +0000659 public:
660};
661#else
Richard Trieu583e2c12017-03-04 00:08:58 +0000662T *t;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000663// expected-error@second.h:* {{'AllDecls::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
664// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
665#endif
666}
667
668namespace FriendFunction {
669#if defined(FIRST)
670void F(int = 0);
671struct S { friend void F(int); };
672#elif defined(SECOND)
673void F(int);
674struct S { friend void F(int); };
675#else
676S s;
677#endif
678
679#if defined(FIRST)
680void G(int = 0);
681struct T {
682 friend void G(int);
683
684 private:
685};
686#elif defined(SECOND)
687void G(int);
688struct T {
689 friend void G(int);
690
691 public:
692};
693#else
694T t;
695// expected-error@second.h:* {{'FriendFunction::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
696// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
697#endif
698} // namespace FriendFunction
699
700namespace ImplicitDecl {
701#if defined(FIRST)
702struct S { };
703void S_Constructors() {
704 // Trigger creation of implicit contructors
705 S foo;
706 S bar = foo;
707 S baz(bar);
708}
709#elif defined(SECOND)
710struct S { };
711#else
712S s;
713#endif
714
715#if defined(FIRST)
716struct T {
717 private:
718};
719void T_Constructors() {
720 // Trigger creation of implicit contructors
721 T foo;
722 T bar = foo;
723 T baz(bar);
724}
725#elif defined(SECOND)
726struct T {
727 public:
728};
729#else
730T t;
731// expected-error@first.h:* {{'ImplicitDecl::T' has different definitions in different modules; first difference is definition in module 'FirstModule' found private access specifier}}
732// expected-note@second.h:* {{but in 'SecondModule' found public access specifier}}
733#endif
734
735} // namespace ImplicitDelc
736
737namespace TemplatedClass {
738#if defined(FIRST)
739template <class>
740struct S {};
741#elif defined(SECOND)
742template <class>
743struct S {};
744#else
745S<int> s;
746#endif
747
748#if defined(FIRST)
749template <class>
750struct T {
751 private:
752};
753#elif defined(SECOND)
754template <class>
755struct T {
756 public:
757};
758#else
759T<int> t;
760// expected-error@second.h:* {{'TemplatedClass::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
761// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
762#endif
763} // namespace TemplatedClass
764
765namespace TemplateClassWithField {
766#if defined(FIRST)
767template <class A>
768struct S {
769 A a;
770};
771#elif defined(SECOND)
772template <class A>
773struct S {
774 A a;
775};
776#else
777S<int> s;
778#endif
779
780#if defined(FIRST)
781template <class A>
782struct T {
783 A a;
784
785 private:
786};
787#elif defined(SECOND)
788template <class A>
789struct T {
790 A a;
791
792 public:
793};
794#else
795T<int> t;
796// expected-error@second.h:* {{'TemplateClassWithField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found public access specifier}}
797// expected-note@first.h:* {{but in 'FirstModule' found private access specifier}}
798#endif
799} // namespace TemplateClassWithField
800
801namespace TemplateClassWithTemplateField {
802#if defined(FIRST)
803template <class A>
804class WrapperS;
805template <class A>
806struct S {
807 WrapperS<A> a;
808};
809#elif defined(SECOND)
810template <class A>
811class WrapperS;
812template <class A>
813struct S {
814 WrapperS<A> a;
815};
816#else
817template <class A>
818class WrapperS{};
819S<int> s;
820#endif
821
822#if defined(FIRST)
823template <class A>
824class WrapperT;
825template <class A>
826struct T {
827 WrapperT<A> a;
828
829 public:
830};
831#elif defined(SECOND)
832template <class A>
833class WrapperT;
834template <class A>
835struct T {
836 WrapperT<A> a;
837
838 private:
839};
840#else
841template <class A>
842class WrapperT{};
843T<int> t;
844// expected-error@second.h:* {{'TemplateClassWithTemplateField::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
845// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
846#endif
847} // namespace TemplateClassWithTemplateField
848
849namespace EnumWithForwardDeclaration {
850#if defined(FIRST)
851enum E : int;
852struct S {
853 void get(E) {}
854};
855#elif defined(SECOND)
856enum E : int { A, B };
857struct S {
858 void get(E) {}
859};
860#else
861S s;
862#endif
863
864#if defined(FIRST)
865struct T {
866 void get(E) {}
867 public:
868};
869#elif defined(SECOND)
870struct T {
871 void get(E) {}
872 private:
873};
874#else
875T t;
876// expected-error@second.h:* {{'EnumWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
877// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
878#endif
879} // namespace EnumWithForwardDeclaration
880
881namespace StructWithForwardDeclaration {
882#if defined(FIRST)
883struct P {};
884struct S {
885 struct P *ptr;
886};
887#elif defined(SECOND)
888struct S {
889 struct P *ptr;
890};
891#else
892S s;
893#endif
894
895#if defined(FIRST)
896struct Q {};
897struct T {
898 struct Q *ptr;
899 public:
900};
901#elif defined(SECOND)
902struct T {
903 struct Q *ptr;
904 private:
905};
906#else
907T t;
908// expected-error@second.h:* {{'StructWithForwardDeclaration::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
909// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
910#endif
911} // namespace StructWithForwardDeclaration
912
913namespace StructWithForwardDeclarationNoDefinition {
914#if defined(FIRST)
915struct P;
916struct S {
917 struct P *ptr;
918};
919#elif defined(SECOND)
920struct S {
921 struct P *ptr;
922};
923#else
924S s;
925#endif
926
927#if defined(FIRST)
928struct Q;
929struct T {
930 struct Q *ptr;
931
932 public:
933};
934#elif defined(SECOND)
935struct T {
936 struct Q *ptr;
937
938 private:
939};
940#else
941T t;
942// expected-error@second.h:* {{'StructWithForwardDeclarationNoDefinition::T' has different definitions in different modules; first difference is definition in module 'SecondModule' found private access specifier}}
943// expected-note@first.h:* {{but in 'FirstModule' found public access specifier}}
944#endif
945} // namespace StructWithForwardDeclarationNoDefinition
946
947// Keep macros contained to one file.
948#ifdef FIRST
949#undef FIRST
950#endif
951#ifdef SECOND
952#undef SECOND
953#endif