68 lines · cpp
1// RUN: rm -rf %t2// RUN: split-file %s %t3// RUN: cd %t4 5// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header-unit-header std-10-6-ex1-decl.h \6// RUN: -o decl.pcm7 8// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header-unit-header std-10-6-ex1-defn.h \9// RUN: -o defn.pcm10 11// RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-stuff.cpp \12// RUN: -o stuff.pcm13 14// RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-M1.cpp \15// RUN: -fmodule-file=stuff=stuff.pcm -o M1.pcm -fmodule-file=defn.pcm16 17// RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-M2.cpp \18// RUN: -fmodule-file=stuff=stuff.pcm -o M2.pcm -fmodule-file=decl.pcm19 20// RUN: %clang_cc1 -std=c++20 std-10-6-ex1-use.cpp \21// RUN: -fmodule-file=M1=M1.pcm -fmodule-file=M2=M2.pcm -fmodule-file=stuff=stuff.pcm \22// RUN: -fsyntax-only -verify23 24//--- std-10-6-ex1-decl.h25struct X;26 27//--- std-10-6-ex1-defn.h28struct X {};29 30//--- std-10-6-ex1-stuff.cpp31export module stuff;32export template <typename T, typename U> void foo(T, U u) { auto v = u; }33export template <typename T, typename U> void bar(T, U u) { auto v = *u; }34 35//--- std-10-6-ex1-M1.cpp36export module M1;37import "std-10-6-ex1-defn.h"; // provides struct X {};38import stuff;39 40export template <typename T> void f(T t) {41 X x;42 foo(t, x);43}44 45//--- std-10-6-ex1-M2.cpp46export module M2;47import "std-10-6-ex1-decl.h"; // provides struct X; (not a definition)48 49import stuff;50export template <typename T> void g(T t) {51 X *x;52 bar(t, x);53}54 55//--- std-10-6-ex1-use.cpp56import M1;57import M2;58 59void test() {60 f(0);61 // It is unspecified whether the instantiation of g(0) is valid here.62 // We choose to make it invalid here.63 g(0); // expected-error@* {{definition of 'X' must be imported from module}}64 // expected-note@* {{in instantiation of function template specialization 'bar<int, X *>'}}65 // expected-note@* {{in instantiation of function template specialization}}66 // expected-note@* {{definition here is not reachable}}67}68