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
21 T templ_func(T t) { return t; }
28 // If we copy foo.h directly, there are other warnings.
34 T templ_func(T t) { return t; }
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}}
53 // These declarations are in the same TU. The compiler should complain.
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}}
67 // These declarations are in the same TU and the redefinitions are in the named modules.
68 // The compiler should complain.
74 // FIXME: The diagnostic message looks not so good.
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}}
85 // These declarations are in the same TU. The compiler should complain.
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}}
102 export using ::templ_func;
108 // These declarations are not in the same TU. The compiler shouldn't complain.
109 // expected-no-diagnostics
114 // These declarations are not in the same TU. The compiler shouldn't complain.
115 // expected-no-diagnostics