blob: eee9c239d188d56972bcfca544839a466a365b99 [file] [log] [blame]
Richard Smith7b5a8bf2017-08-25 02:25:07 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++17 -pedantic -verify %s
Richard Smith9b2c5e72018-09-28 01:16:43 +00002// RUN: %clang_cc1 -fsyntax-only -std=c++2a -Wc++17-compat-pedantic -verify %s -Wno-defaulted-function-deleted
Richard Smith7b5a8bf2017-08-25 02:25:07 +00003
4struct A {};
5int (A::*pa)() const&;
6int 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++2a 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++2a}}
11#endif
12
13struct 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++2a extension}}
18#else
19 // expected-warning@-4 {{explicit capture of 'this' with a capture default of '=' is incompatible with C++ standards before C++2a}}
20#endif
21 }
Richard Smith8b633442017-08-28 00:31:35 +000022
23 int n : 5 = 0;
24#if __cplusplus <= 201703L
25 // expected-warning@-2 {{default member initializer for bit-field is a C++2a extension}}
26#else
27 // expected-warning@-4 {{default member initializer for bit-field is incompatible with C++ standards before C++2a}}
28#endif
Richard Smith7b5a8bf2017-08-25 02:25:07 +000029};
Richard Smith864949b2018-09-27 22:47:04 +000030
31auto Lambda = []{};
32decltype(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++2a}}
37#endif
38
39void 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++2a}}
44#endif
Richard Smith9b2c5e72018-09-28 01:16:43 +000045
46struct DefaultDeleteWrongTypeBase {
47 DefaultDeleteWrongTypeBase(DefaultDeleteWrongTypeBase&);
48};
49struct 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++2a}}
55#endif
56};
Richard Smith8baa5002018-09-28 18:44:09 +000057
58void 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++2a extension}}
62#else
63 // expected-warning@-4 {{range-based for loop initialization statements are incompatible with C++ standards before C++2a}}
64#endif
65}