| 1 |
// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s |
| 2 |
// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected,since-cxx11 %s |
| 3 |
// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected,since-cxx11 %s |
| 4 |
// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected,since-cxx11 %s |
| 5 |
// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx11,since-cxx20 %s |
| 6 |
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23 %s |
| 7 |
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23,since-cxx26 %s |
| 8 |
|
| 9 |
// cxx98-no-diagnostics |
| 10 |
|
| 11 |
namespace cwg2913 { // cwg2913: 20 |
| 12 |
|
| 13 |
#if __cplusplus >= 202002L |
| 14 |
|
| 15 |
template<typename T> |
| 16 |
struct R { |
| 17 |
R(T); |
| 18 |
R(T, T); |
| 19 |
}; |
| 20 |
|
| 21 |
template<typename T> |
| 22 |
R(T) -> R<T> requires true; |
| 23 |
|
| 24 |
template<typename T> |
| 25 |
R(T, T) requires true -> R<T>; |
| 26 |
// since-cxx20-error@-1 {{expected function body after function declarator}} |
| 27 |
|
| 28 |
#endif |
| 29 |
|
| 30 |
} // namespace cwg2913 |
| 31 |
|
| 32 |
namespace cwg2915 { // cwg2915: 20 |
| 33 |
#if __cplusplus >= 202302L |
| 34 |
struct A { |
| 35 |
void f(this void); |
| 36 |
// since-cxx23-error@-1 {{explicit object parameter cannot have 'void' type}} |
| 37 |
}; |
| 38 |
#endif |
| 39 |
} // namespace cwg2915 |
| 40 |
|
| 41 |
namespace cwg2917 { // cwg2917: 20 review 2024-07-30 |
| 42 |
#if __cplusplus >= 201103L |
| 43 |
template <typename> |
| 44 |
class Foo; |
| 45 |
|
| 46 |
template<class ...> |
| 47 |
struct C { |
| 48 |
struct Nested { }; |
| 49 |
}; |
| 50 |
|
| 51 |
struct S { |
| 52 |
template <typename> |
| 53 |
friend class Foo, int; |
| 54 |
// since-cxx11-error@-1 {{a friend declaration that befriends a template must contain exactly one type-specifier}} |
| 55 |
|
| 56 |
template <typename ...Ts> |
| 57 |
friend class C<Ts>::Nested...; |
| 58 |
// since-cxx11-error@-1 {{friend declaration expands pack 'Ts' that is declared it its own template parameter list}} |
| 59 |
}; |
| 60 |
#endif |
| 61 |
} // namespace cwg2917 |
| 62 |
|
| 63 |
namespace cwg2918 { // cwg2918: 21 |
| 64 |
|
| 65 |
#if __cplusplus >= 202002L |
| 66 |
|
| 67 |
namespace Example1 { |
| 68 |
|
| 69 |
template<bool B> struct X { |
| 70 |
void f(short) requires B; |
| 71 |
void f(long); |
| 72 |
template<typename> void g(short) requires B; |
| 73 |
template<typename> void g(long); |
| 74 |
}; |
| 75 |
|
| 76 |
void test() { |
| 77 |
&X<true>::f; // since-cxx20-error {{reference to overloaded function could not be resolved}} |
| 78 |
&X<true>::g<int>; // since-cxx20-error {{reference to overloaded function could not be resolved}} |
| 79 |
} |
| 80 |
|
| 81 |
} // namespace Example1 |
| 82 |
|
| 83 |
namespace Example2 { |
| 84 |
|
| 85 |
template <bool B> struct X { |
| 86 |
static constexpr int f(short) requires B { |
| 87 |
return 42; |
| 88 |
} |
| 89 |
static constexpr int f(short) { |
| 90 |
return 24; |
| 91 |
} |
| 92 |
}; |
| 93 |
|
| 94 |
template <typename T> |
| 95 |
constexpr int f(T) { return 1; } |
| 96 |
|
| 97 |
template <typename T> |
| 98 |
requires __is_same(T, int) |
| 99 |
constexpr int f(T) { return 2; } |
| 100 |
|
| 101 |
void test() { |
| 102 |
constexpr auto x = &X<true>::f; |
| 103 |
static_assert(__is_same(decltype(x), int(*const)(short)), ""); |
| 104 |
static_assert(x(0) == 42, ""); |
| 105 |
|
| 106 |
constexpr auto y = &X<false>::f; |
| 107 |
static_assert(__is_same(decltype(y), int(*const)(short))); |
| 108 |
static_assert(y(0) == 24, ""); |
| 109 |
|
| 110 |
constexpr auto z = &f<int>; |
| 111 |
static_assert(__is_same(decltype(z), int(*const)(int))); |
| 112 |
static_assert(z(0) == 2, ""); |
| 113 |
|
| 114 |
// C++ [temp.deduct.call]p6: |
| 115 |
// If the argument is an overload set containing one or more function templates, |
| 116 |
// the parameter is treated as a non-deduced context. |
| 117 |
auto w = f; // since-cxx20-error {{variable 'w' with type 'auto' has incompatible initializer of type '<overloaded function type>'}} |
| 118 |
} |
| 119 |
|
| 120 |
} // namespace Example2 |
| 121 |
#endif |
| 122 |
|
| 123 |
#if __cplusplus >= 201103L |
| 124 |
namespace Example3 { |
| 125 |
|
| 126 |
template <typename T> void f(T &&, void (*)(T &&)); // #cwg2918_f |
| 127 |
|
| 128 |
void g(int &); |
| 129 |
inline namespace A { |
| 130 |
void g(short &&); |
| 131 |
} |
| 132 |
inline namespace B { |
| 133 |
void g(short &&); |
| 134 |
} |
| 135 |
|
| 136 |
void q() { |
| 137 |
int x; |
| 138 |
f(x, g); |
| 139 |
// since-cxx11-error@-1 {{no matching function for call to 'f'}} |
| 140 |
// since-cxx11-note@#cwg2918_f {{candidate template ignored: deduced conflicting types for parameter 'T' ('int &' vs. 'short')}} |
| 141 |
} |
| 142 |
|
| 143 |
} // namespace Example3 |
| 144 |
|
| 145 |
#endif |
| 146 |
|
| 147 |
} // namespace cwg2918 |
| 148 |
|
| 149 |
#if __cplusplus > 202302L |
| 150 |
namespace std { |
| 151 |
using size_t = decltype(sizeof(0)); |
| 152 |
} // namespace std |
| 153 |
void *operator new(std::size_t, void *p) { return p; } |
| 154 |
void* operator new[] (std::size_t, void* p) {return p; } |
| 155 |
#endif |
| 156 |
|
| 157 |
namespace cwg2922 { // cwg2922: 20 |
| 158 |
#if __cplusplus > 202302L |
| 159 |
union U { int a, b; }; |
| 160 |
constexpr U nondeterministic(bool i) { |
| 161 |
if(i) { |
| 162 |
U u; |
| 163 |
new (&u) int(); // #cwg2922-placement-new |
| 164 |
return u; |
| 165 |
} |
| 166 |
return {}; |
| 167 |
} |
| 168 |
constexpr U _ = nondeterministic(true); |
| 169 |
// since-cxx26-error@-1 {{constexpr variable '_' must be initialized by a constant expression}} |
| 170 |
// since-cxx26-note@#cwg2922-placement-new {{placement new would change type of storage from 'U' to 'int'}} |
| 171 |
// since-cxx26-note@-3 {{in call to 'nondeterministic(true)'}} |
| 172 |
#endif |
| 173 |
} // namespace cwg2922 |