xref: /llvm-project/clang/test/Modules/module-local-with-templates.cppm (revision c5e4afe6733c58e24023ede04275bbed3bde8240)
1// RUN: rm -rf %t
2// RUN: mkdir -p %t
3// RUN: split-file %s %t
4//
5// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
6// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
7// RUN: %clang_cc1 -std=c++20 %t/a-part.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
8//
9// Test again with reduced BMI
10// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
11// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
12// RUN: %clang_cc1 -std=c++20 %t/a-part.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
13// RUN: %clang_cc1 -std=c++20 %t/a.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
14
15
16//--- a.cppm
17export module a;
18
19constexpr int x = 43;
20
21export constexpr int f() { return x; }
22
23export template <typename T>
24constexpr T g() {
25    return x;
26}
27
28namespace nn {
29
30constexpr int x = 88;
31
32export constexpr int f() { return x; }
33
34export template <typename T>
35constexpr T g() {
36    return x;
37}
38}
39
40//--- use.cc
41// expected-no-diagnostics
42import a;
43
44static_assert(f() == 43, "");
45
46constexpr int x = 99;
47
48static_assert(g<int>() == 43, "");
49
50static_assert(x == 99, "");
51
52namespace nn {
53static_assert(f() == 88, "");
54
55constexpr int x = 1000;
56
57static_assert(g<int>() == 88, "");
58
59static_assert(x == 1000, "");
60
61}
62
63//--- a-part.cppm
64module a:impl;
65import a;
66
67static_assert(x == 43, "");
68
69constexpr int x = 1000; // expected-error {{redefinition of 'x'}}
70                        // expected-note@* {{previous definition is here}}
71
72//--- a.cc
73module a;
74
75static_assert(x == 43, "");
76
77constexpr int x = 1000; // expected-error {{redefinition of 'x'}}
78                        // expected-note@* {{previous definition is here}}
79
80