Debian Codegraph @

clang/test/CXX/basic/basic.link/p19.cppm

raw
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface -verify %t/A.cppm -o %t/A.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/A.cpp -fmodule-file=A=%t/A.pcm -fsyntax-only -verify
7
8 //--- A.cppm
9 export module A;
10 static void f() {}
11 inline void it() { f(); } // expected-warning {{TU local entity 'f' is exposed}}
12 static inline void its() { f(); } // OK
13 template<int> void g() { its(); } // OK
14 template void g<0>();
15
16 // Developers Note: We didn't track the use in decltype(). But it should be fine
17 // since the underlying type is not TU-local. So we're doing nothing bad in practice.
18 decltype(f) *fp; // error: f (though not its type) is TU-local
19 auto &fr = f; // OK
20 // Developers Note: We didn't track the use across variables. In the current implementation,
21 // we don't know the value of `fr` at compile time, so we failed to detect this.
22 constexpr auto &fr2 = fr; // error: is an exposure of f
23 // Developers Note: But if it is a direct use, we are able to detect it.
24 constexpr auto &fr3 = f; // expected-warning {{TU local entity 'f' is exposed}}
25 constexpr static auto fp2 = fr; // OK
26
27 struct S { void (&ref)(); } s{f}; // OK, value is TU-local
28 constexpr extern struct W { S &s; } wrap{s}; // OK, value is not TU-local
29
30 static auto x = []{f();}; // OK
31 auto x2 = x; // expected-warning {{TU local entity}}
32 // Developers Note: Why is this an exposure?
33 int y = ([]{f();}(),0); // error: the closure type is not TU-local
34 int y2 = (x,0); // OK expected-warning{{left operand of comma operator has no effect}}
35
36 namespace N {
37 struct A {};
38 void adl(A);
39 static void adl(int);
40 }
41 void adl(double);
42
43 inline void h(auto x) { adl(x); } // OK, but certain specializations are exposures
44
45 // Reflection is not supported yet.
46 // constexpr std::meta::info r1 = ^^g<0>; // OK
47 // namespace N2 {
48 // static constexpr std::meta::info r2 = ^^g<1>; // OK, r2 is TU-local
49 // }
50 // constexpr std::meta::info r3 = ^^f; // error: r3 is an exposure of f
51 //
52 // constexpr auto ctx = std::meta::access_context::current();
53 // constexpr std::meta::info r4 =
54 // std::meta::members_of(^^N2, ctx)[0]; // error: r4 is an exposure of N2​::​r2
55
56 //--- A.cpp
57 module A;
58 void other() {
59 g<0>(); // OK, specialization is explicitly instantiated
60 g<1>(); // expected-warning {{instantiation of 'g<1>' triggers reference to TU-local entity 'its' from other TU 'A'}}
61 // Developers Note: To check use of TU-local entity when overload resolution made.
62 h(N::A{}); // error: overload set contains TU-local N​::​adl(int)
63 h(0); // OK, calls adl(double)
64 adl(N::A{}); // OK; N​::​adl(int) not found, calls N​::​adl(N​::​A)
65 fr(); // OK, calls f
66 // Developers Note: To check use of TU-local entity when we're able to detect the TUlocalness
67 // across variables.
68 constexpr auto ptr = fr; // error: fr is not usable in constant expressions here
69
70 constexpr auto fptr = f; // expected-error {{use of undeclared identifier 'f'}}
71 }