Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / temp / temp.constr / temp.constr.order / function-templates.cpp
blobb2fe2cd52006de26b6f7cd088ffcf7fdb430a116
1 // RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
3 template<typename T> requires (sizeof(T) >= 4)
4 // expected-note@-1{{similar constraint expressions not considered equivalent}}
5 bool a() { return false; } // expected-note {{candidate function [with T = unsigned int]}}
7 template<typename T> requires (sizeof(T) >= 4 && sizeof(T) <= 10)
8 // expected-note@-1{{similar constraint expression here}}
9 bool a() { return true; } // expected-note {{candidate function [with T = unsigned int]}}
11 bool av = a<unsigned>(); // expected-error {{call to 'a' is ambiguous}}
13 template<typename T>
14 concept C1 = sizeof(T) >= 4;
16 template<typename T> requires C1<T>
17 constexpr bool b() { return false; }
19 template<typename T> requires (C1<T> && sizeof(T) <= 10)
20 constexpr bool b() { return true; }
22 static_assert(b<int>());
23 static_assert(!b<int[10]>());
25 template<typename T>
26 concept C2 = sizeof(T) > 1 && sizeof(T) <= 8;
28 template<typename T>
29 bool c() { return false; }
31 template<typename T> requires C1<T>
32 bool c() { return true; }
34 template<typename T> requires C1<T>
35 constexpr bool d() { return false; }
37 template<typename T>
38 constexpr bool d() { return true; }
40 static_assert(!d<int>());
42 template<typename T>
43 constexpr int e() { return 1; }
45 template<typename T> requires C1<T> && C2<T>
46 constexpr int e() { return 2; }
48 template<typename T> requires C1<T> || C2<T>
49 constexpr int e() { return 3; }
51 static_assert(e<unsigned>() == 2);
52 static_assert(e<char[10]>() == 3);
53 static_assert(e<char>() == 1);
55 template<class T, class U>
56 concept BiggerThan = sizeof(T) > sizeof(U);
58 template<class T>
59 concept BiggerThanInt = BiggerThan<T, int>;
61 template<class T, class U> requires BiggerThan<T, U>
62 void f() { }
63 // expected-note@-1 {{candidate function [with T = long long, U = int]}}
65 template<class T, class U> requires BiggerThanInt<T>
66 void f() { }
67 // expected-note@-1 {{candidate function [with T = long long, U = int]}}
69 static_assert(sizeof(f<long long, int>()));
70 // expected-error@-1 {{call to 'f' is ambiguous}} \
71 expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}}
73 template<typename T>
74 concept C3 = true;
76 template<typename T>
77 concept C4 = true && C3<T>;
79 template<typename T> requires C3<void>
80 int g() { }
82 template<typename T> requires C4<void>
83 int g() { }
85 static_assert(sizeof(g<int>()));
87 // Regression - used template parameter detection when only first out of
88 // multiple parameters are used
89 template <unsigned> struct X {};
90 template <class...> int h(X<0>);
91 template <unsigned b, class...> int h(X<b>);
92 static_assert(sizeof(h(X<0>{})));