1 // RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify -Wc++1z-extensions %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -DEXT -Wc++1z-extensions %s
3
4 struct [[nodiscard]] S {};
5 S get_s();
6 S& get_s_ref();
7
8 enum [[nodiscard]] E {};
9 E get_e();
10
11 [[nodiscard]] int get_i();
12
f()13 void f() {
14 get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
15 get_i(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
16 get_e(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
17
18 // Okay, warnings are not encouraged
19 get_s_ref();
20 (void)get_s();
21 (void)get_i();
22 (void)get_e();
23 }
24
25 #ifdef EXT
26 // expected-warning@4 {{use of the 'nodiscard' attribute is a C++1z extension}}
27 // expected-warning@8 {{use of the 'nodiscard' attribute is a C++1z extension}}
28 // expected-warning@11 {{use of the 'nodiscard' attribute is a C++1z extension}}
29 #endif
30