1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 // RUN: cd %t
5 //
6 // RUN: %clang_cc1 -std=c++20 M.cpp -emit-module-interface -o M.pcm
7 // RUN: %clang_cc1 -std=c++20 N.cpp -emit-module-interface -o N.pcm \
8 // RUN: -fmodule-file=M.pcm
9 // RUN: %clang_cc1 -std=c++20 Q.cpp -emit-module-interface -o Q.pcm
10 // RUN: %clang_cc1 -std=c++20 Q-impl.cpp -fsyntax-only -fmodule-file=Q.pcm \
11 // RUN: -fmodule-file=N.pcm -verify
12
13 //--- M.cpp
14 export module M;
15 namespace R {
16 export struct X {};
17 export void f(X);
18 } // namespace R
19 namespace S {
20 export void f(R::X, R::X);
21 }
22
23 //--- N.cpp
24 export module N;
25 import M;
26 export R::X make();
27 namespace R {
28 static int g(X);
29 }
30 export template <typename T, typename U>
apply(T t,U u)31 void apply(T t, U u) {
32 f(t, u);
33 g(t);
34 }
35
36 //--- Q.cpp
37 export module Q;
38
39 //--- Q-impl.cpp
40 module Q;
41 import N;
42
43 namespace S {
44 struct Z {
45 template <typename T> operator T();
46 };
47 } // namespace S
test()48 void test() {
49 // OK, decltype(x) is R::X in module M
50 auto x = make();
51
52 // error: R and R::f are not visible here
53 R::f(x); // expected-error {{declaration of 'R' must be imported from module 'N' before it is required}}
54 // [email protected]:4 {{declaration here is not visible}}
55 // expected-error@-2 {{no type named 'f' in namespace 'R'}}
56
57 f(x); // Found by [basic.lookup.argdep] / p4.3
58
59 // error: S::f in module M not considered even though S is an associated
60 // namespace, since the entity Z is in a different module from f.
61 f(x, S::Z()); // expected-error {{no matching function for call to 'f'}}
62 // [email protected]:4 {{candidate function not viable: requires 1 argument, but 2 were provided}}
63
64 // error: S::f is visible in instantiation context, but R::g has internal
65 // linkage and cannot be used outside N.cpp
66 apply(x, S::Z()); // [email protected]:10 {{no matching function for call to 'g'}}
67 // expected-note@-1 {{in instantiation of function template specialization 'apply<R::X, S::Z>' requested here}}
68 }
69