1- // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify -Wc++20-extensions %s
2- // RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify -Wc++17-extensions %s
3- // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -DEXT -Wc++17-extensions -Wc++20-extensions %s
1+ // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify=expected,cxx11,cxx11-17 -pedantic %s
2+ // RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify=expected,cxx11-17,since-cxx17 -pedantic %s
3+ // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify=expected,since-cxx17 -pedantic %s
44
55struct [[nodiscard]] S {};
6+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
67S get_s ();
78S& get_s_ref ();
89
910enum [[nodiscard]] E {};
11+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
1012E get_e ();
1113
1214[[nodiscard]] int get_i ();
15+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
1316[[nodiscard]] volatile int &get_vi ();
17+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
1418
1519void f () {
1620 get_s (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -27,6 +31,7 @@ void f() {
2731}
2832
2933[[nodiscard]] volatile char &(*fp)(); // expected-warning {{'nodiscard' attribute only applies to functions, classes, or enumerations}}
34+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
3035void g () {
3136 fp (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
3237
@@ -63,15 +68,20 @@ void f() {
6368} // namespace PR31526
6469
6570struct [[nodiscard(" reason" )]] ReasonStruct {};
71+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
6672struct LaterReason ;
6773struct [[nodiscard(" later reason" )]] LaterReason {};
74+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
6875
6976ReasonStruct get_reason ();
7077LaterReason get_later_reason ();
7178[[nodiscard(" another reason" )]] int another_reason ();
79+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
7280
7381[[nodiscard(" conflicting reason" )]] int conflicting_reason ();
82+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
7483[[nodiscard(" special reason" )]] int conflicting_reason ();
84+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
7585
7686void cxx20_use () {
7787 get_reason (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: reason}}
@@ -82,17 +92,23 @@ void cxx20_use() {
8292
8393namespace p1771 {
8494struct [[nodiscard(" Don't throw me away!" )]] ConvertTo{};
95+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
8596struct S {
8697 [[nodiscard]] S();
98+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
8799 [[nodiscard(" Don't let that S-Char go!" )]] S(char );
100+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
88101 S (int );
89102 [[gnu::warn_unused_result]] S(double );
90103 operator ConvertTo ();
91104 [[nodiscard]] operator int ();
105+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
92106 [[nodiscard(" Don't throw away as a double" )]] operator double ();
107+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
93108};
94109
95110struct [[nodiscard(" Don't throw me away either!" )]] Y{};
111+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
96112
97113void usage () {
98114 S (); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
@@ -103,42 +119,18 @@ void usage() {
103119 S s;
104120 ConvertTo{}; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
105121
106- // AST is different in C++20 mode, pre-2017 a move ctor for ConvertTo is there
107- // as well, hense the constructor warning.
108- #if __cplusplus >= 201703L
109- // expected-warning@+4 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
110- #else
111- // expected-warning@+2 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
112- #endif
122+ // AST is different in C++17 mode. Before, a move ctor for ConvertTo is there
123+ // as well, hence the constructor warning.
124+
125+ // since-cxx17-warning@+2 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
126+ // cxx11-warning@+1 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
113127 (ConvertTo) s;
114128 (int )s; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
115129 (S)' c' ; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't let that S-Char go!}}
116- #if __cplusplus >= 201703L
117- // expected-warning@+4 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
118- #else
119- // expected-warning@+2 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
120- #endif
130+ // since-cxx17-warning@+2 {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
131+ // cxx11-warning@+1 {{ignoring temporary created by a constructor declared with 'nodiscard' attribute: Don't throw me away!}}
121132 static_cast <ConvertTo>(s);
122133 static_cast <int >(s); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
123134 static_cast <double >(s); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw away as a double}}
124135}
125- }; // namespace p1771
126-
127- #ifdef EXT
128- // expected-warning@5 {{use of the 'nodiscard' attribute is a C++17 extension}}
129- // expected-warning@9 {{use of the 'nodiscard' attribute is a C++17 extension}}
130- // expected-warning@12 {{use of the 'nodiscard' attribute is a C++17 extension}}
131- // expected-warning@13 {{use of the 'nodiscard' attribute is a C++17 extension}}
132- // expected-warning@29 {{use of the 'nodiscard' attribute is a C++17 extension}}
133- // expected-warning@65 {{use of the 'nodiscard' attribute is a C++20 extension}}
134- // expected-warning@67 {{use of the 'nodiscard' attribute is a C++20 extension}}
135- // expected-warning@71 {{use of the 'nodiscard' attribute is a C++20 extension}}
136- // expected-warning@73 {{use of the 'nodiscard' attribute is a C++20 extension}}
137- // expected-warning@74 {{use of the 'nodiscard' attribute is a C++20 extension}}
138- // expected-warning@84 {{use of the 'nodiscard' attribute is a C++20 extension}}
139- // expected-warning@86 {{use of the 'nodiscard' attribute is a C++17 extension}}
140- // expected-warning@87 {{use of the 'nodiscard' attribute is a C++20 extension}}
141- // expected-warning@91 {{use of the 'nodiscard' attribute is a C++17 extension}}
142- // expected-warning@92 {{use of the 'nodiscard' attribute is a C++20 extension}}
143- // expected-warning@95 {{use of the 'nodiscard' attribute is a C++20 extension}}
144- #endif
136+ } // namespace p1771
0 commit comments