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
4
4
5
5
struct [[nodiscard]] S {};
6
+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
6
7
S get_s ();
7
8
S& get_s_ref ();
8
9
9
10
enum [[nodiscard]] E {};
11
+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
10
12
E get_e ();
11
13
12
14
[[nodiscard]] int get_i ();
15
+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
13
16
[[nodiscard]] volatile int &get_vi ();
17
+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
14
18
15
19
void f () {
16
20
get_s (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -27,6 +31,7 @@ void f() {
27
31
}
28
32
29
33
[[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}}
30
35
void g () {
31
36
fp (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
32
37
@@ -63,15 +68,20 @@ void f() {
63
68
} // namespace PR31526
64
69
65
70
struct [[nodiscard(" reason" )]] ReasonStruct {};
71
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
66
72
struct LaterReason ;
67
73
struct [[nodiscard(" later reason" )]] LaterReason {};
74
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
68
75
69
76
ReasonStruct get_reason ();
70
77
LaterReason get_later_reason ();
71
78
[[nodiscard(" another reason" )]] int another_reason ();
79
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
72
80
73
81
[[nodiscard(" conflicting reason" )]] int conflicting_reason ();
82
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
74
83
[[nodiscard(" special reason" )]] int conflicting_reason ();
84
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
75
85
76
86
void cxx20_use () {
77
87
get_reason (); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: reason}}
@@ -82,17 +92,23 @@ void cxx20_use() {
82
92
83
93
namespace p1771 {
84
94
struct [[nodiscard(" Don't throw me away!" )]] ConvertTo{};
95
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
85
96
struct S {
86
97
[[nodiscard]] S();
98
+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
87
99
[[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}}
88
101
S (int );
89
102
[[gnu::warn_unused_result]] S(double );
90
103
operator ConvertTo ();
91
104
[[nodiscard]] operator int ();
105
+ // cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
92
106
[[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}}
93
108
};
94
109
95
110
struct [[nodiscard(" Don't throw me away either!" )]] Y{};
111
+ // cxx11-17-warning@-1 {{use of the 'nodiscard' attribute is a C++20 extension}}
96
112
97
113
void usage () {
98
114
S (); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
@@ -103,42 +119,18 @@ void usage() {
103
119
S s;
104
120
ConvertTo{}; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw me away!}}
105
121
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!}}
113
127
(ConvertTo) s;
114
128
(int )s; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
115
129
(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!}}
121
132
static_cast <ConvertTo>(s);
122
133
static_cast <int >(s); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
123
134
static_cast <double >(s); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Don't throw away as a double}}
124
135
}
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