236
|
1 // Tests that redefinitions in different TUs could be merged correctly and the
|
|
2 // redefinitions in the same TUs could be merged diagnosticed correctly.
|
|
3 //
|
|
4 // RUN: rm -rf %t
|
|
5 // RUN: mkdir %t
|
|
6 // RUN: split-file %s %t
|
|
7 //
|
|
8 // RUN: %clang_cc1 -std=c++20 -I%t %t/normal.cpp -verify -fsyntax-only
|
|
9 // RUN: %clang_cc1 -std=c++20 -I%t %t/M1.cppm -verify -fsyntax-only
|
|
10 // RUN: %clang_cc1 -std=c++20 -I%t %t/M2.cppm -verify -fsyntax-only
|
|
11 // RUN: %clang_cc1 -std=c++20 -I%t %t/M3.cppm -verify -fsyntax-only
|
|
12 // RUN: %clang_cc1 -std=c++20 -I%t %t/M.cppm -emit-module-interface -o %t/M.pcm
|
|
13 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use1.cpp -verify -fsyntax-only
|
|
14 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use2.cpp -verify -fsyntax-only
|
|
15 //
|
|
16 //--- foo.h
|
|
17 #ifndef FOO
|
|
18 #define FOO
|
|
19 inline void func() {}
|
|
20 template <typename T>
|
|
21 T templ_func(T t) { return t; }
|
|
22 struct S {};
|
|
23 template <class C>
|
|
24 struct T { C c; };
|
|
25 inline int v = 43;
|
|
26 #endif
|
|
27
|
|
28 // If we copy foo.h directly, there are other warnings.
|
|
29 //--- redef.h
|
|
30 #ifndef REDEF
|
|
31 #define REDEF
|
|
32 inline void func() {}
|
|
33 template <typename T>
|
|
34 T templ_func(T t) { return t; }
|
|
35 struct S {};
|
|
36 template <class C>
|
|
37 struct T { C c; };
|
|
38 inline int v = 43;
|
|
39 #endif
|
|
40
|
|
41 //--- normal.cpp
|
|
42 #include "foo.h"
|
|
43 #include "redef.h"
|
|
44
|
|
45 // expected-error@* {{redefinition of 'func'}}
|
|
46 // expected-error@* {{redefinition of 'templ_func'}}
|
|
47 // expected-error@* {{redefinition of 'S'}}
|
|
48 // expected-error@* {{redefinition of 'T'}}
|
|
49 // expected-error@* {{redefinition of 'v'}}
|
|
50 // expected-note@* 1+{{previous definition is here}}
|
|
51
|
|
52 //--- M1.cppm
|
|
53 // These declarations are in the same TU. The compiler should complain.
|
|
54 module;
|
|
55 #include "foo.h"
|
|
56 #include "redef.h"
|
|
57 export module M1;
|
|
58
|
|
59 // expected-error@* {{redefinition of 'func'}}
|
|
60 // expected-error@* {{redefinition of 'templ_func'}}
|
|
61 // expected-error@* {{redefinition of 'S'}}
|
|
62 // expected-error@* {{redefinition of 'T'}}
|
|
63 // expected-error@* {{redefinition of 'v'}}
|
|
64 // expected-note@* 1+{{previous definition is here}}
|
|
65
|
|
66 //--- M2.cppm
|
|
67 // These declarations are in the same TU and the redefinitions are in the named modules.
|
|
68 // The compiler should complain.
|
|
69 module;
|
|
70 #include "foo.h"
|
|
71 export module M2;
|
|
72 #include "redef.h"
|
|
73
|
|
74 // FIXME: The diagnostic message looks not so good.
|
|
75 //
|
|
76 // expected-error@* {{declaration of 'func' in module M2 follows declaration in the global module}}
|
|
77 // expected-error@* {{declaration of 'templ_func' in module M2 follows declaration in the global module}}
|
|
78 // expected-error@* {{redefinition of 'S'}}
|
|
79 // expected-error@* {{redefinition of 'T'}}
|
|
80 // expected-error@* {{declaration of 'v' in module M2 follows declaration in the global module}}
|
|
81 // expected-note@* 1+{{previous definition is here}}
|
|
82 // expected-note@* 1+{{previous declaration is here}}
|
|
83
|
|
84 //--- M3.cppm
|
|
85 // These declarations are in the same TU. The compiler should complain.
|
|
86 export module M3;
|
|
87 #include "foo.h"
|
|
88 #include "redef.h"
|
|
89
|
|
90 // expected-error@* {{redefinition of 'func'}}
|
|
91 // expected-error@* {{redefinition of 'templ_func'}}
|
|
92 // expected-error@* {{redefinition of 'S'}}
|
|
93 // expected-error@* {{redefinition of 'T'}}
|
|
94 // expected-error@* {{redefinition of 'v'}}
|
|
95 // expected-note@* 1+{{previous definition is here}}
|
|
96
|
|
97 //--- M.cppm
|
|
98 module;
|
|
99 #include "foo.h"
|
|
100 export module M;
|
|
101 export using ::func;
|
|
102 export using ::templ_func;
|
|
103 export using ::S;
|
|
104 export using ::T;
|
|
105 export using ::v;
|
|
106
|
|
107 //--- Use1.cpp
|
|
108 // These declarations are not in the same TU. The compiler shouldn't complain.
|
|
109 // expected-no-diagnostics
|
|
110 #include "foo.h"
|
|
111 import M;
|
|
112
|
|
113 //--- Use2.cpp
|
|
114 // These declarations are not in the same TU. The compiler shouldn't complain.
|
|
115 // expected-no-diagnostics
|
|
116 import M;
|
|
117 #include "foo.h"
|