annotate clang/test/Modules/redefinition-merges.cppm @ 266:00f31e85ec16 default tip

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