aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Modules/merge-concepts.cppm
blob: f8a763adaff661a53e6168691d9d72695d0da4e8 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/A.cppm -o %t/A.pcm
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -I%t %t/B.cppm -o %t/B.pcm
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use2.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use3.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use4.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/C.cppm -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -I%t %t/D.cppm -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -I%t %t/E.cppm -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -I%t %t/F.cppm -verify -fsyntax-only
//
// Testing header units for coverity.
// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/foo.h -o %t/foo.pcm
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -fmodule-file=%t/foo.pcm %t/Use5.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -fmodule-file=%t/foo.pcm %t/Use6.cpp -verify -fsyntax-only
//
// Testing with module map modules. It is unclear about the relation ship between Clang modules and
// C++20 Named Modules. Will they coexist? Or will they be mutually exclusive?
// The test here is for primarily coverity.
//
// RUN: rm -f %t/foo.pcm
// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fprebuilt-module-path=%t \
// RUN:   -fmodule-map-file=%t/module.modulemap %t/Use7.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fprebuilt-module-path=%t \
// RUN:   -fmodule-map-file=%t/module.modulemap %t/Use7.cpp -verify -fsyntax-only
// Testing module map modules with named modules.
// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%t/module.modulemap \
// RUN:   %t/A.cppm -o %t/A.pcm
// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fprebuilt-module-path=%t \
// RUN:   -fmodule-map-file=%t/module.modulemap %t/Use7.cpp -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -fmodules -fmodules-cache-path=%t -fprebuilt-module-path=%t \
// RUN:   -fmodule-map-file=%t/module.modulemap %t/Use7.cpp -verify -fsyntax-only

//
//--- foo.h
#ifndef FOO_H
#define FOO_H
template <class T, class U>
concept same_as = __is_same(T, U);
#endif

// The compiler would warn if we include foo_h twice without guard.
//--- redecl.h
#ifndef REDECL_H
#define REDECL_H
template <class T, class U>
concept same_as = __is_same(T, U);
#endif

//--- A.cppm
module;
#include "foo.h"
export module A;
export using ::same_as;

//--- B.cppm
module;
#include "foo.h"
export module B;
export using ::same_as;

//--- Use.cpp
// expected-no-diagnostics
import A;
import B;

template <class T> void foo()
  requires same_as<T, int>
{}

//--- Use2.cpp
// expected-no-diagnostics
#include "foo.h"
import A;

template <class T> void foo()
  requires same_as<T, int>
{}

//--- Use3.cpp
// expected-no-diagnostics
import A;
#include "foo.h"

template <class T> void foo()
  requires same_as<T, int>
{}

//--- Use4.cpp
// expected-no-diagnostics
import A;
import B;
#include "foo.h"

template <class T> void foo()
  requires same_as<T, int>
{}

//--- C.cppm
// expected-no-diagnostics
module;
#include "foo.h"
export module C;
import A;
import B;

template <class T> void foo()
  requires same_as<T, int>
{}

//--- D.cppm
module;
#include "foo.h"
#include "redecl.h"
export module D;
export using ::same_as;

// expected-error@* {{redefinition of 'same_as'}}
// expected-note@* 1+{{previous definition is here}}

//--- E.cppm
module;
#include "foo.h"
export module E;
export template <class T, class U>
concept same_as = __is_same(T, U);

// expected-error@* {{redefinition of 'same_as'}}
// expected-note@* 1+{{previous definition is here}}

//--- F.cppm
export module F;
template <class T, class U>
concept same_as = __is_same(T, U);
template <class T, class U>
concept same_as = __is_same(T, U);

// expected-error@* {{redefinition of 'same_as'}}
// expected-note@* 1+{{previous definition is here}}

//--- Use5.cpp
import "foo.h";  // expected-warning {{the implementation of header units is in an experimental phase}}
import A;

template <class T> void foo()
  requires same_as<T, int>
{}

//--- Use6.cpp
import A;
import "foo.h"; // expected-warning {{the implementation of header units is in an experimental phase}}

template <class T> void foo()
  requires same_as<T, int>
{}

//--- module.modulemap
module "foo" {
  export * 
  header "foo.h"
}

//--- Use7.cpp
// expected-no-diagnostics
#include "foo.h"
import A;

template <class T> void foo()
  requires same_as<T, int>
{}

//--- Use8.cpp
// expected-no-diagnostics
import A;
#include "foo.h"

template <class T> void foo()
  requires same_as<T, int>
{}