| 1 |
// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s |
| 2 |
// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected %s |
| 3 |
// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected %s |
| 4 |
// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected %s |
| 5 |
// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx20 %s |
| 6 |
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx20,since-cxx23 %s |
| 7 |
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx20,since-cxx23,since-cxx26 %s |
| 8 |
|
| 9 |
|
| 10 |
int main() {} // required for cwg2811 |
| 11 |
|
| 12 |
namespace cwg2811 { // cwg2811: 3.5 |
| 13 |
#if __cplusplus >= 201103L |
| 14 |
void f() { |
| 15 |
(void)[&] { |
| 16 |
using T = decltype(main); |
| 17 |
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}} |
| 18 |
}; |
| 19 |
using T2 = decltype(main); |
| 20 |
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}} |
| 21 |
} |
| 22 |
|
| 23 |
using T = decltype(main); |
| 24 |
// expected-error@-1 {{referring to 'main' within an expression is a Clang extension}} |
| 25 |
|
| 26 |
int main(); |
| 27 |
|
| 28 |
using U = decltype(main); |
| 29 |
using U2 = decltype(&main); |
| 30 |
#endif |
| 31 |
} // namespace cwg2811 |
| 32 |
|
| 33 |
namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01 |
| 34 |
#if __cpp_constexpr >= 202306L |
| 35 |
constexpr void* p = nullptr; |
| 36 |
constexpr int* q = static_cast<int*>(p); |
| 37 |
static_assert(q == nullptr); |
| 38 |
#endif |
| 39 |
} |
| 40 |
|
| 41 |
namespace cwg2847 { // cwg2847: 19 review 2024-03-01 |
| 42 |
|
| 43 |
#if __cplusplus >= 202002L |
| 44 |
|
| 45 |
template<typename> |
| 46 |
void i(); |
| 47 |
|
| 48 |
struct A { |
| 49 |
template<typename> |
| 50 |
void f() requires true; |
| 51 |
|
| 52 |
template<> |
| 53 |
void f<int>() requires true; |
| 54 |
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} |
| 55 |
|
| 56 |
friend void i<int>() requires true; |
| 57 |
// since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}} |
| 58 |
}; |
| 59 |
|
| 60 |
template<typename> |
| 61 |
struct B { |
| 62 |
void f() requires true; |
| 63 |
|
| 64 |
template<typename> |
| 65 |
void g() requires true; |
| 66 |
|
| 67 |
template<typename> |
| 68 |
void h() requires true; |
| 69 |
|
| 70 |
template<> |
| 71 |
void h<int>() requires true; |
| 72 |
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} |
| 73 |
|
| 74 |
friend void i<int>() requires true; |
| 75 |
// since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}} |
| 76 |
}; |
| 77 |
|
| 78 |
template<> |
| 79 |
void B<int>::f() requires true; |
| 80 |
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} |
| 81 |
|
| 82 |
template<> |
| 83 |
template<typename T> |
| 84 |
void B<int>::g() requires true; |
| 85 |
|
| 86 |
#endif |
| 87 |
|
| 88 |
} // namespace cwg2847 |
| 89 |
|
| 90 |
namespace cwg2857 { // cwg2857: no |
| 91 |
struct A {}; |
| 92 |
template <typename> |
| 93 |
struct D; |
| 94 |
namespace N { |
| 95 |
struct B {}; |
| 96 |
void adl_only(A*, D<int>*); // #cwg2857-adl_only |
| 97 |
} |
| 98 |
|
| 99 |
void f(A* a, D<int>* d) { |
| 100 |
adl_only(a, d); |
| 101 |
// expected-error@-1 {{use of undeclared identifier 'adl_only'; did you mean 'N::adl_only'?}} |
| 102 |
// expected-note@#cwg2857-adl_only {{'N::adl_only' declared here}} |
| 103 |
} |
| 104 |
|
| 105 |
#if __cplusplus >= 201103L |
| 106 |
template <typename> |
| 107 |
struct D : N::B { |
| 108 |
// FIXME: ADL shouldn't associate it's base B and N since D is not complete here |
| 109 |
decltype(adl_only((A*) nullptr, (D*) nullptr)) f; |
| 110 |
}; |
| 111 |
#endif |
| 112 |
} // namespace cwg2857 |
| 113 |
|
| 114 |
namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05 |
| 115 |
|
| 116 |
#if __cplusplus > 202302L |
| 117 |
|
| 118 |
template<typename... Ts> |
| 119 |
struct A { |
| 120 |
// FIXME: The nested-name-specifier in the following friend declarations are declarative, |
| 121 |
// but we don't treat them as such (yet). |
| 122 |
friend void Ts...[0]::f(); |
| 123 |
template<typename U> |
| 124 |
friend void Ts...[0]::g(); |
| 125 |
|
| 126 |
friend struct Ts...[0]::B; |
| 127 |
// FIXME: The index of the pack-index-specifier is printed as a memory address in the diagnostic. |
| 128 |
template<typename U> |
| 129 |
friend struct Ts...[0]::C; |
| 130 |
// expected-warning-re@-1 {{dependent nested name specifier 'Ts...[{{.*}}]::' for friend template declaration is not supported; ignoring this friend declaration}} |
| 131 |
}; |
| 132 |
|
| 133 |
#endif |
| 134 |
|
| 135 |
} // namespace cwg2858 |
| 136 |
|
| 137 |
namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31 |
| 138 |
#if __cplusplus >= 202002L |
| 139 |
enum E { x }; |
| 140 |
void f() { |
| 141 |
int E; |
| 142 |
using enum E; // OK, names ::E |
| 143 |
} |
| 144 |
using F = E; |
| 145 |
using enum F; // OK, designates ::E |
| 146 |
template<class T> using EE = T; |
| 147 |
void g() { |
| 148 |
using enum EE<E>; // OK, designates ::E |
| 149 |
} |
| 150 |
#endif |
| 151 |
} // namespace cwg2877 |
| 152 |
|
| 153 |
namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19 |
| 154 |
|
| 155 |
#if __cplusplus >= 202302L |
| 156 |
|
| 157 |
template <typename T> struct A : T {}; |
| 158 |
template <typename T> struct B : T {}; |
| 159 |
template <typename T> struct C : virtual T { C(T t) : T(t) {} }; |
| 160 |
template <typename T> struct D : virtual T { D(T t) : T(t) {} }; |
| 161 |
|
| 162 |
template <typename Ts> |
| 163 |
struct O1 : A<Ts>, B<Ts> { |
| 164 |
using A<Ts>::operator(); |
| 165 |
using B<Ts>::operator(); |
| 166 |
}; |
| 167 |
|
| 168 |
template <typename Ts> struct O2 : protected Ts { // expected-note {{declared protected here}} |
| 169 |
using Ts::operator(); |
| 170 |
O2(Ts ts) : Ts(ts) {} |
| 171 |
}; |
| 172 |
|
| 173 |
template <typename Ts> struct O3 : private Ts { // expected-note {{declared private here}} |
| 174 |
using Ts::operator(); |
| 175 |
O3(Ts ts) : Ts(ts) {} |
| 176 |
}; |
| 177 |
|
| 178 |
// Not ambiguous because of virtual inheritance. |
| 179 |
template <typename Ts> |
| 180 |
struct O4 : C<Ts>, D<Ts> { |
| 181 |
using C<Ts>::operator(); |
| 182 |
using D<Ts>::operator(); |
| 183 |
O4(Ts t) : Ts(t), C<Ts>(t), D<Ts>(t) {} |
| 184 |
}; |
| 185 |
|
| 186 |
// This still has a public path to the lambda, and it's also not |
| 187 |
// ambiguous because of virtual inheritance. |
| 188 |
template <typename Ts> |
| 189 |
struct O5 : private C<Ts>, D<Ts> { |
| 190 |
using C<Ts>::operator(); |
| 191 |
using D<Ts>::operator(); |
| 192 |
O5(Ts t) : Ts(t), C<Ts>(t), D<Ts>(t) {} |
| 193 |
}; |
| 194 |
|
| 195 |
// This is only invalid if we call T's call operator. |
| 196 |
template <typename T, typename U> |
| 197 |
struct O6 : private T, U { // expected-note {{declared private here}} |
| 198 |
using T::operator(); |
| 199 |
using U::operator(); |
| 200 |
O6(T t, U u) : T(t), U(u) {} |
| 201 |
}; |
| 202 |
|
| 203 |
void f() { |
| 204 |
int x; |
| 205 |
auto L1 = [=](this auto&& self) { (void) &x; }; |
| 206 |
auto L2 = [&](this auto&& self) { (void) &x; }; |
| 207 |
O1<decltype(L1)>{L1, L1}(); // expected-error {{inaccessible due to ambiguity}} |
| 208 |
O1<decltype(L2)>{L2, L2}(); // expected-error {{inaccessible due to ambiguity}} |
| 209 |
O2{L1}(); // expected-error {{must derive publicly from the lambda}} |
| 210 |
O3{L1}(); // expected-error {{must derive publicly from the lambda}} |
| 211 |
O4{L1}(); |
| 212 |
O5{L1}(); |
| 213 |
O6 o{L1, L2}; |
| 214 |
o.decltype(L1)::operator()(); // expected-error {{must derive publicly from the lambda}} |
| 215 |
o.decltype(L1)::operator()(); // No error here because we've already diagnosed this method. |
| 216 |
o.decltype(L2)::operator()(); |
| 217 |
} |
| 218 |
|
| 219 |
#endif |
| 220 |
|
| 221 |
} // namespace cwg2881 |
| 222 |
|
| 223 |
namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31 |
| 224 |
struct C { |
| 225 |
operator void() = delete; |
| 226 |
// expected-warning@-1 {{conversion function converting 'cwg2882::C' to 'void' will never be used}} |
| 227 |
// cxx98-error@-2 {{deleted function definitions are a C++11 extension}} |
| 228 |
}; |
| 229 |
|
| 230 |
void f(C c) { |
| 231 |
(void)c; |
| 232 |
} |
| 233 |
} // namespace cwg2882 |
| 234 |
|
| 235 |
namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31 |
| 236 |
#if __cplusplus >= 201103L |
| 237 |
void f() { |
| 238 |
int x; |
| 239 |
(void)[&] { |
| 240 |
return x; |
| 241 |
}; |
| 242 |
} |
| 243 |
#endif |
| 244 |
#if __cplusplus >= 202002L |
| 245 |
struct A { |
| 246 |
A() = default; |
| 247 |
A(const A &) = delete; // #cwg2883-A-copy-ctor |
| 248 |
constexpr operator int() { return 42; } |
| 249 |
}; |
| 250 |
void g() { |
| 251 |
constexpr A a; |
| 252 |
// FIXME: OK, not odr-usable from a default template argument, and not odr-used |
| 253 |
(void)[=]<typename T, int = a> {}; |
| 254 |
// since-cxx20-error@-1 {{call to deleted constructor of 'const A'}} |
| 255 |
// since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked deleted here}} |
| 256 |
} |
| 257 |
#endif |
| 258 |
} // namespace cwg2883 |
| 259 |
|
| 260 |
namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31 |
| 261 |
#if __cplusplus >= 202002L |
| 262 |
template <class T> |
| 263 |
struct A { |
| 264 |
A() requires (false) = default; |
| 265 |
A() : t(42) {} |
| 266 |
T t; |
| 267 |
}; |
| 268 |
|
| 269 |
struct B : A<int> {}; |
| 270 |
static_assert(!__is_trivially_constructible(B)); |
| 271 |
#endif |
| 272 |
} // namespace cwg2885 |
| 273 |
|
| 274 |
namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31 |
| 275 |
#if __cplusplus >= 201103L |
| 276 |
struct C { |
| 277 |
C() = default; |
| 278 |
~C() noexcept(false) = default; |
| 279 |
}; |
| 280 |
|
| 281 |
static_assert(noexcept(C()), ""); |
| 282 |
#endif |
| 283 |
} // namespace cwg2886 |