72 lines · plain
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4//5// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface -verify %t/A.cppm -o %t/A.pcm6// RUN: %clang_cc1 -std=c++20 %t/A.cpp -fmodule-file=A=%t/A.pcm -fsyntax-only -verify7 8//--- A.cppm9export module A;10static void f() {}11inline void it() { f(); } // expected-warning {{TU local entity 'f' is exposed}}12static inline void its() { f(); } // OK13template<int> void g() { its(); } // OK14template void g<0>();15 16// Developers Note: We didn't track the use in decltype(). But it should be fine17// since the underlying type is not TU-local. So we're doing nothing bad in practice.18decltype(f) *fp; // error: f (though not its type) is TU-local19auto &fr = f; // OK20// 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.22constexpr auto &fr2 = fr; // error: is an exposure of f23// Developers Note: But if it is a direct use, we are able to detect it.24constexpr auto &fr3 = f; // expected-warning {{TU local entity 'f' is exposed}}25constexpr static auto fp2 = fr; // OK26 27struct S { void (&ref)(); } s{f}; // OK, value is TU-local28constexpr extern struct W { S &s; } wrap{s}; // OK, value is not TU-local29 30static auto x = []{f();}; // OK31auto x2 = x; // expected-warning {{TU local entity}}32// Developers Note: Why is this an exposure?33int y = ([]{f();}(),0); // error: the closure type is not TU-local34int y2 = (x,0); // OK expected-warning{{left operand of comma operator has no effect}}35 36namespace N {37 struct A {};38 void adl(A);39 static void adl(int);40}41void adl(double);42 43inline void h(auto x) { adl(x); } // OK, but certain specializations are exposures44 45// Reflection is not supported yet.46// constexpr std::meta::info r1 = ^^g<0>; // OK47// namespace N2 {48// static constexpr std::meta::info r2 = ^^g<1>; // OK, r2 is TU-local49// }50// constexpr std::meta::info r3 = ^^f; // error: r3 is an exposure of f51// 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::r255 56//--- A.cpp57module A;58void other() {59 g<0>(); // OK, specialization is explicitly instantiated60 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 f66 // Developers Note: To check use of TU-local entity when we're able to detect the TUlocalness67 // across variables.68 constexpr auto ptr = fr; // error: fr is not usable in constant expressions here69 70 constexpr auto fptr = f; // expected-error {{use of undeclared identifier 'f'}}71}72