aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Modules/module-local-with-templates.cppm
blob: 87955bdd3f99ee41904979bd14cd2b23b7196d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
// RUN: %clang_cc1 -std=c++20 %t/a-part.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
//
// Test again with reduced BMI
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
// RUN: %clang_cc1 -std=c++20 %t/use.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
// RUN: %clang_cc1 -std=c++20 %t/a-part.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
// RUN: %clang_cc1 -std=c++20 %t/a.cc -fmodule-file=a=%t/a.pcm -fsyntax-only -verify


//--- a.cppm
export module a;

constexpr int x = 43;

export constexpr int f() { return x; }

export template <typename T>
constexpr T g() {
    return x;
}

namespace nn {

constexpr int x = 88;

export constexpr int f() { return x; }

export template <typename T>
constexpr T g() {
    return x;
}
}

//--- use.cc
// expected-no-diagnostics
import a;

static_assert(f() == 43, "");

constexpr int x = 99;

static_assert(g<int>() == 43, "");

static_assert(x == 99, "");

namespace nn {
static_assert(f() == 88, "");

constexpr int x = 1000;

static_assert(g<int>() == 88, "");

static_assert(x == 1000, "");

}

//--- a-part.cppm
module a:impl;
import a;

static_assert(x == 43, "");

constexpr int x = 1000; // expected-error {{redefinition of 'x'}}
                        // expected-note@* {{previous definition is here}}

//--- a.cc
module a;

static_assert(x == 43, "");

constexpr int x = 1000; // expected-error {{redefinition of 'x'}}
                        // expected-note@* {{previous definition is here}}