[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / template-function-specialization.cpp
blobd5d7d7e8123988e44fb58bcdfe97b339300709a9
1 // RUN: rm -fr %t
2 // RUN: mkdir %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/foo.cppm -o %t/foo.pcm
6 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only
8 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/foo.cppm -o %t/foo.pcm
9 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only -DREDUCED
11 //--- foo.cppm
12 module;
13 # 3 __FILE__ 1 // use the next physical line number here (and below)
14 template <typename T>
15 void foo() {
18 template <>
19 void foo<int>() {
22 template <typename T>
23 void foo2() {
26 template <>
27 void foo2<int>() {
30 template <typename T>
31 void foo3() {
34 template <>
35 void foo3<int>();
37 export module foo;
38 export using ::foo;
39 export using ::foo3;
41 export template <typename T>
42 void foo4() {
45 export template <>
46 void foo4<int>() {
49 //--- Use.cpp
50 import foo;
51 void use() {
52 foo<short>();
53 foo<int>();
54 #ifdef REDUCED
55 // In reduced BMI, the foo2 template function is optimized out.
56 foo2<short>(); // expected-error {{use of undeclared identifier 'foo2'}}
57 foo2<int>(); // expected-error {{use of undeclared identifier 'foo2'}}
58 #else
59 foo2<short>(); // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
60 // expected-note@* {{declaration here is not visible}}
61 foo2<int>(); // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
62 // expected-note@* {{declaration here is not visible}}
63 #endif
64 foo3<short>();
65 foo3<int>();
67 foo4<short>();
68 foo4<int>();