| 1 |
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s |
| 3 |
|
| 4 |
// Member function declarations with the same name and the same |
| 5 |
// parameter-type-list as well as mem- ber function template |
| 6 |
// declarations with the same name, the same parameter-type-list, and |
| 7 |
// the same template parameter lists cannot be overloaded if any of |
| 8 |
// them, but not all, have a ref-qualifier (8.3.5). |
| 9 |
|
| 10 |
class Y { |
| 11 |
void h() &; |
| 12 |
void h() const &; |
| 13 |
void h() &&; |
| 14 |
void i() &; // expected-note{{previous declaration}} |
| 15 |
void i() const; // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} |
| 16 |
|
| 17 |
template<typename T> void f(T*) &; |
| 18 |
template<typename T> void f(T*) &&; |
| 19 |
|
| 20 |
template<typename T> void g(T*) &; // expected-note{{previous declaration}} |
| 21 |
template<typename T> void g(T*); // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}} |
| 22 |
|
| 23 |
void k(); // expected-note{{previous declaration}} |
| 24 |
void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}} |
| 25 |
}; |
| 26 |
|
| 27 |
struct GH76358 { |
| 28 |
template<int> void f() && {} |
| 29 |
template<typename T> void f() const {} |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
#if __cplusplus >= 202002L |
| 34 |
namespace GH58962 { |
| 35 |
|
| 36 |
template<typename T> |
| 37 |
__add_rvalue_reference(T) declval(); |
| 38 |
|
| 39 |
template<unsigned R> |
| 40 |
struct type |
| 41 |
{ |
| 42 |
void func() requires (R == 0); |
| 43 |
void func() & requires (R == 1); |
| 44 |
void func() && requires (R == 2); |
| 45 |
}; |
| 46 |
|
| 47 |
template<typename T> |
| 48 |
concept test = requires { declval<T>().func(); }; |
| 49 |
|
| 50 |
static_assert(test<type<0>&>); |
| 51 |
static_assert(test<type<0>&&>); |
| 52 |
static_assert(test<type<1>&>); |
| 53 |
static_assert(not test<type<1>&&>); |
| 54 |
static_assert(not test<type<2>&>); |
| 55 |
static_assert(test<type<2>&&>); |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
namespace GH78101 { |
| 60 |
|
| 61 |
template<typename T, typename U, int i> |
| 62 |
concept True = true; |
| 63 |
|
| 64 |
template<typename T, int I> |
| 65 |
struct Template { |
| 66 |
static constexpr int i = I; |
| 67 |
friend constexpr auto operator+(True<T, i> auto f) { |
| 68 |
return i; |
| 69 |
} |
| 70 |
}; |
| 71 |
|
| 72 |
template<int I> |
| 73 |
struct Template<float, I> { |
| 74 |
static constexpr int i = I; |
| 75 |
friend constexpr auto operator+(True<float, i> auto f) { |
| 76 |
return i; |
| 77 |
} |
| 78 |
}; |
| 79 |
|
| 80 |
Template<void, 4> f{}; |
| 81 |
static_assert(+Template<float, 5>{} == 5); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
#endif |