1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -pedantic -verify %s
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wc++17-compat-pedantic -verify %s -Wno-defaulted-function-deleted
struct A {};
int (A::*pa)() const&;
int use_pa = (A().*pa)();
#if __cplusplus <= 201703L
// expected-warning@-2 {{invoking a pointer to a 'const &' member function on an rvalue is a C++20 extension}}
#else
// expected-warning@-4 {{invoking a pointer to a 'const &' member function on an rvalue is incompatible with C++ standards before C++20}}
#endif
struct B {
void b() {
(void) [=, this] {};
#if __cplusplus <= 201703L
// expected-warning@-2 {{explicit capture of 'this' with a capture default of '=' is a C++20 extension}}
#else
// expected-warning@-4 {{explicit capture of 'this' with a capture default of '=' is incompatible with C++ standards before C++20}}
#endif
}
int n : 5 = 0;
#if __cplusplus <= 201703L
// expected-warning@-2 {{default member initializer for bit-field is a C++20 extension}}
#else
// expected-warning@-4 {{default member initializer for bit-field is incompatible with C++ standards before C++20}}
#endif
};
auto Lambda = []{};
decltype(Lambda) AnotherLambda;
#if __cplusplus <= 201703L
// expected-error@-2 {{no matching constructor}} expected-note@-3 2{{candidate}}
#else
// expected-warning@-4 {{default construction of lambda is incompatible with C++ standards before C++20}}
#endif
void copy_lambda() { Lambda = Lambda; }
#if __cplusplus <= 201703L
// expected-error@-2 {{deleted}} expected-note@-10 {{lambda}}
#else
// expected-warning@-4 {{assignment of lambda is incompatible with C++ standards before C++20}}
#endif
struct DefaultDeleteWrongTypeBase {
DefaultDeleteWrongTypeBase(DefaultDeleteWrongTypeBase&);
};
struct DefaultDeleteWrongType : DefaultDeleteWrongTypeBase {
DefaultDeleteWrongType(const DefaultDeleteWrongType&) = default;
#if __cplusplus <= 201703L
// expected-error@-2 {{a member or base requires it to be non-const}}
#else
// expected-warning@-4 {{explicitly defaulting this copy constructor with a type different from the implicit type is incompatible with C++ standards before C++20}}
#endif
};
void ForRangeInit() {
for (int arr[3] = {1, 2, 3}; int n : arr) {}
#if __cplusplus <= 201703L
// expected-warning@-2 {{range-based for loop initialization statements are a C++20 extension}}
#else
// expected-warning@-4 {{range-based for loop initialization statements are incompatible with C++ standards before C++20}}
#endif
}
struct ConstexprVirtual {
virtual constexpr void f() {}
#if __cplusplus <= 201703L
// expected-error@-2 {{virtual function cannot be constexpr}}
#else
// expected-warning@-4 {{virtual constexpr functions are incompatible with C++ standards before C++20}}
#endif
};
struct C { int x, y, z; };
static auto [cx, cy, cz] = C();
#if __cplusplus <= 201703L
// expected-warning@-2 {{decomposition declaration declared 'static' is a C++20 extension}}
#else
// expected-warning@-4 {{decomposition declaration declared 'static' is incompatible with C++ standards before C++20}}
#endif
void f() {
static thread_local auto [cx, cy, cz] = C();
#if __cplusplus <= 201703L
// expected-warning@-2 {{decomposition declaration declared with 'static thread_local' specifiers is a C++20 extension}}
#else
// expected-warning@-4 {{decomposition declaration declared with 'static thread_local' specifiers is incompatible with C++ standards before C++20}}
#endif
}
struct DefaultedComparisons {
bool operator==(const DefaultedComparisons&) const = default;
bool operator!=(const DefaultedComparisons&) const = default;
#if __cplusplus <= 201703L
// expected-warning@-3 {{defaulted comparison operators are a C++20 extension}}
// expected-warning@-3 {{defaulted comparison operators are a C++20 extension}}
#else
// expected-warning@-6 {{defaulted comparison operators are incompatible with C++ standards before C++20}}
// expected-warning@-6 {{defaulted comparison operators are incompatible with C++ standards before C++20}}
#endif
bool operator<=>(const DefaultedComparisons&) const = default;
#if __cplusplus <= 201703L
// expected-error@-2 {{'operator<=' cannot be the name of a variable or data member}} expected-error@-2 0+{{}} expected-warning@-2 {{}}
#else
// expected-warning@-4 {{'<=>' operator is incompatible with C++ standards before C++20}}
#endif
bool operator<(const DefaultedComparisons&) const = default;
bool operator<=(const DefaultedComparisons&) const = default;
bool operator>(const DefaultedComparisons&) const = default;
bool operator>=(const DefaultedComparisons&) const = default;
#if __cplusplus <= 201703L
// expected-error@-5 {{only special member functions}}
// expected-error@-5 {{only special member functions}}
// expected-error@-5 {{only special member functions}}
// expected-error@-5 {{only special member functions}}
#else
// expected-warning@-10 {{defaulted comparison operators are incompatible with C++ standards before C++20}}
// expected-warning@-10 {{defaulted comparison operators are incompatible with C++ standards before C++20}}
// expected-warning@-10 {{defaulted comparison operators are incompatible with C++ standards before C++20}}
// expected-warning@-10 {{defaulted comparison operators are incompatible with C++ standards before C++20}}
#endif
};
namespace NTTP {
struct A {};
template<A> struct Class {};
#if __cplusplus <= 201703L
// expected-error@-2 {{non-type template parameter cannot have type 'A' before C++20}}
#else
// expected-warning@-4 {{non-type template parameter of type 'A' is incompatible with C++ standards before C++20}}
#endif
}
namespace CTADForAliasTemplate {
template<typename T> struct A { A(T); };
template<typename T> using B = A<T>;
B b = {1};
#if __cplusplus <= 201703L
// FIXME: diagnose as well
#else
// expected-warning@-4 {{class template argument deduction for alias templates is incompatible with C++ standards before C++20}}
#endif
}
|