59 lines · plain
1// RUN: rm -rf %t2// RUN: mkdir %t3// RUN: split-file %s %t4 5// RUN: %clang_cc1 -std=c++20 %t/std-10-4-ex2-interface.cppm -emit-reduced-module-interface \6// RUN: -o %t/M.pcm -Wno-unused-value7// RUN: %clang_cc1 -std=c++20 %t/std-10-4-ex2-implementation.cpp -fmodule-file=M=%t/M.pcm \8// RUN: -fsyntax-only -verify -Wno-unused-value9 10//--- std-10-4-ex2.h11 12namespace N {13struct X {};14int d();15int e();16inline int f(X, int = d()) { return e(); }17int g(X);18int h(X);19} // namespace N20 21//--- std-10-4-ex2-interface.cppm22module;23#include "std-10-4-ex2.h"24export module M;25 26template <typename T> int use_f() {27 N::X x; // N::X, N, and :: are decl-reachable from use_f28 return f(x, 123); // N::f is decl-reachable from use_f,29 // N::e is indirectly decl-reachable from use_f30 // because it is decl-reachable from N::f, and31 // N::d is decl-reachable from use_f32 // because it is decl-reachable from N::f33 // even though it is not used in this call34}35 36template <typename T> int use_g() {37 N::X x; // N::X, N, and :: are decl-reachable from use_g38 return g((T(), x)); // N::g is not decl-reachable from use_g39}40 41template <typename T> int use_h() {42 N::X x; // N::X, N, and :: are decl-reachable from use_h43 return h((T(), x)); // N::h is not decl-reachable from use_h, but44 // N::h is decl-reachable from use_h<int>45}46 47int k = use_h<int>();48// use_h<int> is decl-reachable from k, so49// N::h is decl-reachable from k50 51//--- std-10-4-ex2-implementation.cpp52module M;53 54int a = use_f<int>();55int b = use_g<int>();56// expected-error@std-10-4-ex2-interface.cppm:17 {{use of undeclared identifier 'g'}}57// expected-note@-2 {{in instantiation of function template specialization 'use_g<int>' requested here}}58int c = use_h<int>();59