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