Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / basic / basic.lookup / basic.lookup.argdep / p5-ex2.cpp
blobc1a824bd51493202cc2ad83696403aa74b437684
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=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=Q.pcm \
11 // RUN: -fmodule-file=N=N.pcm -fmodule-file=M=M.pcm -verify
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);
23 //--- N.cpp
24 export module N;
25 import M;
26 export R::X make();
27 namespace R {
28 static int g(X);
30 export template <typename T, typename U>
31 void apply(T t, U u) {
32 f(t, u);
33 g(t);
36 //--- Q.cpp
37 export module Q;
39 //--- Q-impl.cpp
40 module Q;
41 import N;
43 namespace S {
44 struct Z {
45 template <typename T> operator T();
47 } // namespace S
48 void test() {
49 // OK, decltype(x) is R::X in module M
50 auto x = make();
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 // expected-note@N.cpp:4 {{declaration here is not visible}}
55 // expected-error@-2 {{no type named 'f' in namespace 'R'}}
57 f(x); // Found by [basic.lookup.argdep] / p4.3
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 // expected-note@M.cpp:4 {{candidate function not viable: requires 1 argument, but 2 were provided}}
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()); // expected-error@N.cpp: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}}