| 1 |
// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected |
| 2 |
// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected |
| 3 |
// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected |
| 4 |
// RUN: %clang_cc1 -std=c++17 -pedantic-errors %s -verify=expected,since-cxx17 |
| 5 |
// RUN: %clang_cc1 -std=c++20 -pedantic-errors %s -verify=expected,since-cxx17 |
| 6 |
// RUN: %clang_cc1 -std=c++23 -pedantic-errors %s -verify=expected,since-cxx17 |
| 7 |
// RUN: %clang_cc1 -std=c++2c -pedantic-errors %s -verify=expected,since-cxx17 |
| 8 |
|
| 9 |
#if __cplusplus <= 201402L |
| 10 |
// expected-no-diagnostics |
| 11 |
#endif |
| 12 |
|
| 13 |
namespace cwg2406 { // cwg2406: 5 |
| 14 |
#if __cplusplus >= 201703L |
| 15 |
void fallthrough(int n) { |
| 16 |
void g(), h(), i(); |
| 17 |
switch (n) { |
| 18 |
case 1: |
| 19 |
case 2: |
| 20 |
g(); |
| 21 |
[[fallthrough]]; |
| 22 |
case 3: // warning on fallthrough discouraged |
| 23 |
do { |
| 24 |
[[fallthrough]]; |
| 25 |
// since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}} |
| 26 |
} while (false); |
| 27 |
case 6: |
| 28 |
do { |
| 29 |
[[fallthrough]]; |
| 30 |
// since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}} |
| 31 |
} while (n); |
| 32 |
case 7: |
| 33 |
while (false) { |
| 34 |
[[fallthrough]]; |
| 35 |
// since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}} |
| 36 |
} |
| 37 |
case 5: |
| 38 |
h(); |
| 39 |
case 4: // implementation may warn on fallthrough |
| 40 |
i(); |
| 41 |
[[fallthrough]]; |
| 42 |
// since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}} |
| 43 |
} |
| 44 |
} |
| 45 |
#endif |
| 46 |
} |
| 47 |
|
| 48 |
namespace cwg2428 { // cwg2428: 19 |
| 49 |
#if __cplusplus >= 202002L |
| 50 |
template <typename> |
| 51 |
concept C [[deprecated]] = true; // #cwg2428-C |
| 52 |
|
| 53 |
template <typename> |
| 54 |
[[deprecated]] concept C2 = true; |
| 55 |
// expected-error@-1 {{expected unqualified-id}} |
| 56 |
|
| 57 |
template <typename T> |
| 58 |
concept C3 = C<T>; |
| 59 |
// expected-warning@-1 {{'C' is deprecated}} |
| 60 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 61 |
|
| 62 |
template <typename T, C U> |
| 63 |
// expected-warning@-1 {{'C' is deprecated}} |
| 64 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 65 |
requires C<T> |
| 66 |
// expected-warning@-1 {{'C' is deprecated}} |
| 67 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 68 |
void f() { |
| 69 |
bool b = C<int>; |
| 70 |
// expected-warning@-1 {{'C' is deprecated}} |
| 71 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 72 |
}; |
| 73 |
|
| 74 |
void g(C auto a) {}; |
| 75 |
// expected-warning@-1 {{'C' is deprecated}} |
| 76 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 77 |
|
| 78 |
template <typename T> |
| 79 |
auto h() -> C auto { |
| 80 |
// expected-warning@-1 {{'C' is deprecated}} |
| 81 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 82 |
C auto foo = T(); |
| 83 |
// expected-warning@-1 {{'C' is deprecated}} |
| 84 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 85 |
C auto *bar = T(); |
| 86 |
// expected-warning@-1 {{'C' is deprecated}} |
| 87 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 88 |
C auto &baz = T(); |
| 89 |
// expected-warning@-1 {{'C' is deprecated}} |
| 90 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 91 |
C auto &&quux = T(); |
| 92 |
// expected-warning@-1 {{'C' is deprecated}} |
| 93 |
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}} |
| 94 |
return foo; |
| 95 |
} |
| 96 |
#endif |
| 97 |
} // namespace cwg2428 |
| 98 |
|
| 99 |
namespace cwg2430 { // cwg2430: 2.7 |
| 100 |
struct S { |
| 101 |
S f(S s) { return s; } |
| 102 |
}; |
| 103 |
} // namespace cwg2430 |
| 104 |
|
| 105 |
namespace cwg2450 { // cwg2450: 18 |
| 106 |
#if __cplusplus >= 202302L |
| 107 |
struct S {int a;}; |
| 108 |
template <S s> |
| 109 |
void f(){} |
| 110 |
|
| 111 |
void test() { |
| 112 |
f<{0}>(); |
| 113 |
f<{.a= 0}>(); |
| 114 |
} |
| 115 |
|
| 116 |
#endif |
| 117 |
} |
| 118 |
|
| 119 |
namespace cwg2459 { // cwg2459: 18 |
| 120 |
#if __cplusplus >= 202302L |
| 121 |
struct A { |
| 122 |
constexpr A(float) {} |
| 123 |
}; |
| 124 |
template<A> struct X {}; |
| 125 |
X<1> x; |
| 126 |
#endif |
| 127 |
} |
| 128 |
|
| 129 |
namespace cwg2445 { // cwg2445: 19 |
| 130 |
#if __cplusplus >= 202002L |
| 131 |
template <typename> constexpr bool F = false; |
| 132 |
template <typename T> struct A { }; |
| 133 |
|
| 134 |
template <typename T, typename U> |
| 135 |
bool operator==(T, A<U *>); |
| 136 |
|
| 137 |
template <typename T, typename U> |
| 138 |
bool operator!=(A<T>, U) { |
| 139 |
static_assert(F<T>, "Isn't this less specialized?"); |
| 140 |
return false; |
| 141 |
} |
| 142 |
|
| 143 |
bool f(A<int> ax, A<int *> ay) { return ay != ax; } |
| 144 |
|
| 145 |
template<class T> concept AlwaysTrue=true; |
| 146 |
template <class T> struct B { |
| 147 |
template <AlwaysTrue U> |
| 148 |
bool operator==(const B<U>&)const; |
| 149 |
}; |
| 150 |
|
| 151 |
|
| 152 |
template <typename U> |
| 153 |
bool operator==(const B<int>&,const B<U>&) { |
| 154 |
static_assert(F<int>, "Isn't this less specialized?"); |
| 155 |
return false; |
| 156 |
} |
| 157 |
|
| 158 |
bool g(B<int> bx, B<int *> by) { return bx == by; } |
| 159 |
|
| 160 |
struct C{ |
| 161 |
template<AlwaysTrue T> |
| 162 |
int operator+(T){return 0;} |
| 163 |
template<class T> |
| 164 |
void operator-(T){} |
| 165 |
}; |
| 166 |
template<class T> |
| 167 |
void operator+(C&&,T){} |
| 168 |
template<AlwaysTrue T> |
| 169 |
int operator-(C&&,T){return 0;} |
| 170 |
|
| 171 |
void t(int* iptr){ |
| 172 |
int x1 = C{} + iptr; |
| 173 |
int x2 = C{} - iptr; |
| 174 |
} |
| 175 |
|
| 176 |
struct D{ |
| 177 |
template<AlwaysTrue T> |
| 178 |
int operator+(T) volatile {return 1;} |
| 179 |
}; |
| 180 |
|
| 181 |
template<class T> |
| 182 |
void operator+(volatile D&,T) {} |
| 183 |
|
| 184 |
int foo(volatile D& d){ |
| 185 |
return d + 1; |
| 186 |
} |
| 187 |
#endif |
| 188 |
} |