| 1 |
// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify |
| 2 |
|
| 3 |
// expected-no-diagnostics |
| 4 |
|
| 5 |
struct A { |
| 6 |
consteval A operator+() { return {}; } |
| 7 |
}; |
| 8 |
consteval A operator~(A) { return {}; } |
| 9 |
consteval A operator+(A, A) { return {}; } |
| 10 |
|
| 11 |
template <class> void f() { |
| 12 |
A a; |
| 13 |
A b = ~a; |
| 14 |
A c = a + a; |
| 15 |
A d = +a; |
| 16 |
} |
| 17 |
template void f<int>(); |
| 18 |
|
| 19 |
template <class T> void foo() { |
| 20 |
T a; |
| 21 |
T b = ~a; |
| 22 |
T c = a + a; |
| 23 |
T d = +a; |
| 24 |
} |
| 25 |
|
| 26 |
template void foo<A>(); |
| 27 |
|
| 28 |
template <typename DataT> struct B { DataT D; }; |
| 29 |
|
| 30 |
template <typename DataT> |
| 31 |
consteval B<DataT> operator+(B<DataT> lhs, B<DataT> rhs) { |
| 32 |
return B<DataT>{lhs.D + rhs.D}; |
| 33 |
} |
| 34 |
|
| 35 |
template <class T> consteval T template_add(T a, T b) { return a + b; } |
| 36 |
|
| 37 |
consteval B<int> non_template_add(B<int> a, B<int> b) { return a + b; } |
| 38 |
|
| 39 |
void bar() { |
| 40 |
constexpr B<int> a{}; |
| 41 |
constexpr B<int> b{}; |
| 42 |
auto constexpr c = a + b; |
| 43 |
} |
| 44 |
|
| 45 |
static_assert((template_add(B<int>{7}, B<int>{3})).D == 10); |
| 46 |
static_assert((non_template_add(B<int>{7}, B<int>{3})).D == 10); |