1 // Tests that the definition in private module fragment is not reachable to its users. 2 // 3 // RUN: rm -rf %t 4 // RUN: mkdir -p %t 5 // RUN: split-file %s %t 6 // 7 // RUN: %clang_cc1 -std=c++20 %t/Private.cppm -emit-module-interface -o %t/Private.pcm 8 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only 9 10 //--- Private.cppm 11 export module Private; 12 inline void fn_m(); // OK, module-linkage inline function 13 static void fn_s(); 14 export struct X; 15 g(X * x)16export void g(X *x) { 17 fn_s(); // OK, call to static function in same translation unit 18 fn_m(); // OK, call to module-linkage inline function 19 } 20 export X *factory(); // OK 21 22 module :private; 23 struct X {}; // definition not reachable from importers of A 24 X *factory() { 25 return new X(); 26 } 27 void fn_m() {} 28 void fn_s() {} 29 30 //--- Use.cpp 31 import Private; 32 void foo() { 33 X x; // expected-error {{definition of 'X' must be imported from module 'Private.<private>' before it is required}} 34 // expected-error@-1 {{definition of 'X' must be imported from module 'Private.<private>' before it is required}} 35 // expected-note@* {{definition here is not reachable}} 36 // expected-note@* {{definition here is not reachable}} 37 auto _ = factory(); 38 auto *__ = factory(); 39 X *___ = factory(); 40 41 g(__); 42 g(___); 43 g(factory()); 44 } 45