aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Modules/string-literal-uniqueness.cpp
blob: 34adc2b0303bdf5185aeb71fa4a7802d79879fcb (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
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t

// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/a.cpp \
// RUN:  -o %t/A.pcm

// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/b.cpp \
// RUN:  -fmodule-file=A=%t/A.pcm -o %t/B.pcm

// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/c.cpp \
// RUN:  -fmodule-file=A=%t/A.pcm -o %t/C.pcm

// RUN: %clang_cc1 -std=c++20 -verify %t/main.cpp \
// RUN:  -fmodule-file=A=%t/A.pcm \
// RUN:  -fmodule-file=B=%t/B.pcm \
// RUN:  -fmodule-file=C=%t/C.pcm

// expected-no-diagnostics

//--- a.cpp

export module A;
export consteval const char *hello() { return "hello"; }
export constexpr const char *helloA0 = hello();
export constexpr const char *helloA1 = helloA0;
export constexpr const char *helloA2 = hello();

//--- b.cpp

export module B;
import A;
export constexpr const char *helloB1 = helloA0;
export constexpr const char *helloB2 = hello();

//--- c.cpp

export module C;
import A;
export constexpr const char *helloC1 = helloA1;
export constexpr const char *helloC2 = hello();

//--- main.cpp

import A;
import B;
import C;

// These are valid: they refer to the same evaluation of the same constant.
static_assert(helloA0 == helloA1);
static_assert(helloA0 == helloB1);
static_assert(helloA0 == helloC1);

// These refer to distinct evaluations, and so may or may not be equal.
static_assert(helloA1 == helloA2); // expected-error {{}} expected-note {{unspecified value}}
static_assert(helloA1 == helloB2); // expected-error {{}} expected-note {{unspecified value}}
static_assert(helloA1 == helloC2); // expected-error {{}} expected-note {{unspecified value}}
static_assert(helloA2 == helloB2); // expected-error {{}} expected-note {{unspecified value}}
static_assert(helloA2 == helloC2); // expected-error {{}} expected-note {{unspecified value}}
static_assert(helloB2 == helloC2); // expected-error {{}} expected-note {{unspecified value}}