Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / merge-constrained-friends.cpp
blob8f0e9ed83cf2962b91df6042b79356d0d3beddc9
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++23 %t/A.cppm -emit-module-interface -o %t/A.pcm
6 // RUN: %clang_cc1 -std=c++23 %t/Use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
8 //--- A.cppm
9 module;
10 export module A;
12 struct B {};
14 export template<int N> struct A : B {
15 friend constexpr const int *f(B) requires true {
16 static constexpr int result = N;
17 return &result;
20 template<int M>
21 friend constexpr const int *g(B) requires (M >= 0) && (N >= 0) {
22 static constexpr int result = M * 10 + N;
23 return &result;
27 export inline A<1> a1;
28 export inline A<2> a2;
29 export inline A<3> a3;
31 static_assert(f(a1) != f(a2) && f(a2) != f(a3));
32 static_assert(g<1>(a1) != g<1>(a2) && g<1>(a2) != g<1>(a3));
34 static_assert(*f(a1) == 1);
35 static_assert(*f(a2) == 2);
36 static_assert(*f(a3) == 3);
38 static_assert(*g<4>(a1) == 41);
39 static_assert(*g<5>(a2) == 52);
40 static_assert(*g<6>(a3) == 63);
42 //--- Use.cpp
43 // expected-no-diagnostics
44 import A;
46 // Try some instantiations we tried before and some we didn't.
47 static_assert(f(a1) != f(a2) && f(a2) != f(a3));
48 static_assert(g<1>(a1) != g<1>(a2) && g<1>(a2) != g<1>(a3));
49 static_assert(g<2>(a1) != g<2>(a2) && g<2>(a2) != g<2>(a3));
51 A<4> a4;
52 static_assert(f(a1) != f(a4) && f(a2) != f(a4) && f(a3) != f(a4));
53 static_assert(g<3>(a1) != g<3>(a4));
55 static_assert(*f(a1) == 1);
56 static_assert(*f(a2) == 2);
57 static_assert(*f(a3) == 3);
58 static_assert(*f(a4) == 4);
60 static_assert(*g<4>(a1) == 41);
61 static_assert(*g<5>(a2) == 52);
62 static_assert(*g<6>(a3) == 63);
64 static_assert(*g<7>(a1) == 71);
65 static_assert(*g<8>(a4) == 84);