xref: /llvm-project/clang/test/Modules/merge-concepts-cxx-modules.cpp (revision da00c60dae0040185dc45039c4397f6e746548e9)
1 // RUN: rm -rf %t
2 // RUN: mkdir %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/same_as.cppm -o %t/same_as.pcm
6 // RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t %t/concepts.cppm -o %t/concepts.pcm
7 // RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t %t/format.cppm -o %t/format.pcm
8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/conflicting.cppm -o %t/conflicting.pcm
9 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cppm -fsyntax-only -verify
10 
11 // Test again with reduced BMI.
12 // RUN: rm -rf %t
13 // RUN: mkdir %t
14 // RUN: split-file %s %t
15 //
16 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/same_as.cppm -o %t/same_as.pcm
17 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface -fprebuilt-module-path=%t %t/concepts.cppm -o %t/concepts.pcm
18 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface -fprebuilt-module-path=%t %t/format.cppm -o %t/format.pcm
19 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/conflicting.cppm -o %t/conflicting.pcm
20 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cppm -fsyntax-only -verify
21 
22 
23 //--- same_as.cppm
24 export module same_as;
25 export template <class T, class U>
26 concept same_as = __is_same(T, U);
27 
28 //--- concepts.cppm
29 export module concepts;
30 export import same_as;
31 
32 export template <class T>
33 concept ConflictingConcept = true;
34 
35 //--- format.cppm
36 
37 export module format;
38 export import concepts;
39 export import same_as;
40 
foo()41 export template <class T> void foo()
42   requires same_as<T, int>
43 {}
44 
45 //--- conflicting.cppm
46 export module conflicting;
47 export template <class T, class U = int>
48 concept ConflictingConcept = true;
49 
50 //--- Use.cppm
51 import format;
52 import conflicting;
53 
foo()54 template <class T> void foo()
55   requires same_as<T, T>
56 {}
57 ConflictingConcept auto x = 10; // expected-error {{reference to 'ConflictingConcept' is ambiguous}}
58                                 // expected-note@* 2 {{candidate}}
59