| 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 |
| 17 |
export module a; |
| 18 |
|
| 19 |
constexpr int x = 43; |
| 20 |
|
| 21 |
export constexpr int f() { return x; } |
| 22 |
|
| 23 |
export template <typename T> |
| 24 |
constexpr T g() { |
| 25 |
return x; |
| 26 |
} |
| 27 |
|
| 28 |
namespace nn { |
| 29 |
|
| 30 |
constexpr int x = 88; |
| 31 |
|
| 32 |
export constexpr int f() { return x; } |
| 33 |
|
| 34 |
export template <typename T> |
| 35 |
constexpr T g() { |
| 36 |
return x; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
//--- use.cc |
| 41 |
// expected-no-diagnostics |
| 42 |
import a; |
| 43 |
|
| 44 |
static_assert(f() == 43, ""); |
| 45 |
|
| 46 |
constexpr int x = 99; |
| 47 |
|
| 48 |
static_assert(g<int>() == 43, ""); |
| 49 |
|
| 50 |
static_assert(x == 99, ""); |
| 51 |
|
| 52 |
namespace nn { |
| 53 |
static_assert(f() == 88, ""); |
| 54 |
|
| 55 |
constexpr int x = 1000; |
| 56 |
|
| 57 |
static_assert(g<int>() == 88, ""); |
| 58 |
|
| 59 |
static_assert(x == 1000, ""); |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
//--- a-part.cppm |
| 64 |
module a:impl; |
| 65 |
import a; |
| 66 |
|
| 67 |
static_assert(x == 43, ""); |
| 68 |
|
| 69 |
constexpr int x = 1000; // expected-error {{redefinition of 'x'}} |
| 70 |
// expected-note@* {{previous definition is here}} |
| 71 |
|
| 72 |
//--- a.cc |
| 73 |
module a; |
| 74 |
|
| 75 |
static_assert(x == 43, ""); |
| 76 |
|
| 77 |
constexpr int x = 1000; // expected-error {{redefinition of 'x'}} |
| 78 |
// expected-note@* {{previous definition is here}} |
| 79 |
|