1 // Tests that redefinitions in different TUs could be merged correctly and the
2 // redefinitions in the same TUs could be merged diagnosticed correctly.
6 // RUN: split-file %s %t
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
16 // / Test again with reduced BMI.
17 // RUN: %clang_cc1 -std=c++20 -I%t %t/M.cppm -emit-reduced-module-interface -o %t/M.pcm
18 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use1.cpp -verify -fsyntax-only
19 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use2.cpp -verify -fsyntax-only
27 T templ_func(T t) { return t; }
34 // If we copy foo.h directly, there are other warnings.
40 T templ_func(T t) { return t; }
51 // expected-error@* {{redefinition of 'func'}}
52 // expected-error@* {{redefinition of 'templ_func'}}
53 // expected-error@* {{redefinition of 'S'}}
54 // expected-error@* {{redefinition of 'T'}}
55 // expected-error@* {{redefinition of 'v'}}
56 // expected-note@* 1+{{previous definition is here}}
59 // These declarations are in the same TU. The compiler should complain.
65 // expected-error@* {{redefinition of 'func'}}
66 // expected-error@* {{redefinition of 'templ_func'}}
67 // expected-error@* {{redefinition of 'S'}}
68 // expected-error@* {{redefinition of 'T'}}
69 // expected-error@* {{redefinition of 'v'}}
70 // expected-note@* 1+{{previous definition is here}}
73 // These declarations are in the same TU and the redefinitions are in the named modules.
74 // The compiler should complain.
80 // FIXME: The diagnostic message looks not so good.
82 // expected-error@* {{declaration of 'func' in module M2 follows declaration in the global module}}
83 // expected-error@* {{declaration of 'templ_func' in module M2 follows declaration in the global module}}
84 // expected-error@* {{redefinition of 'S'}}
85 // expected-error@* {{redefinition of 'T'}}
86 // expected-error@* {{declaration of 'v' in module M2 follows declaration in the global module}}
87 // expected-note@* 1+{{previous definition is here}}
88 // expected-note@* 1+{{previous declaration is here}}
91 // These declarations are in the same TU. The compiler should complain.
96 // expected-error@* {{redefinition of 'func'}}
97 // expected-error@* {{redefinition of 'templ_func'}}
98 // expected-error@* {{redefinition of 'S'}}
99 // expected-error@* {{redefinition of 'T'}}
100 // expected-error@* {{redefinition of 'v'}}
101 // expected-note@* 1+{{previous definition is here}}
108 export using ::templ_func;
114 // These declarations are not in the same TU. The compiler shouldn't complain.
115 // expected-no-diagnostics
120 // These declarations are not in the same TU. The compiler shouldn't complain.
121 // expected-no-diagnostics