Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / Modules / merge-constrained-friends.cpp
blobd0317b99801e970ce10d1a997b5062f40d2838f7
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 // RUN: %clang_cc1 -std=c++23 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm
9 // RUN: %clang_cc1 -std=c++23 %t/Use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
11 //--- A.cppm
12 module;
13 export module A;
15 struct B {};
17 export template<int N> struct A : B {
18 friend constexpr const int *f(B) requires true {
19 static constexpr int result = N;
20 return &result;
23 template<int M>
24 friend constexpr const int *g(B) requires (M >= 0) && (N >= 0) {
25 static constexpr int result = M * 10 + N;
26 return &result;
30 export inline A<1> a1;
31 export inline A<2> a2;
32 export inline A<3> a3;
34 static_assert(f(a1) != f(a2) && f(a2) != f(a3));
35 static_assert(g<1>(a1) != g<1>(a2) && g<1>(a2) != g<1>(a3));
37 static_assert(*f(a1) == 1);
38 static_assert(*f(a2) == 2);
39 static_assert(*f(a3) == 3);
41 static_assert(*g<4>(a1) == 41);
42 static_assert(*g<5>(a2) == 52);
43 static_assert(*g<6>(a3) == 63);
45 //--- Use.cpp
46 // expected-no-diagnostics
47 import A;
49 // Try some instantiations we tried before and some we didn't.
50 static_assert(f(a1) != f(a2) && f(a2) != f(a3));
51 static_assert(g<1>(a1) != g<1>(a2) && g<1>(a2) != g<1>(a3));
52 static_assert(g<2>(a1) != g<2>(a2) && g<2>(a2) != g<2>(a3));
54 A<4> a4;
55 static_assert(f(a1) != f(a4) && f(a2) != f(a4) && f(a3) != f(a4));
56 static_assert(g<3>(a1) != g<3>(a4));
58 static_assert(*f(a1) == 1);
59 static_assert(*f(a2) == 2);
60 static_assert(*f(a3) == 3);
61 static_assert(*f(a4) == 4);
63 static_assert(*g<4>(a1) == 41);
64 static_assert(*g<5>(a2) == 52);
65 static_assert(*g<6>(a3) == 63);
67 static_assert(*g<7>(a1) == 71);
68 static_assert(*g<8>(a4) == 84);