1 // RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s
3 // This is the latest version of nodiscard that we support.
4 _Static_assert(__has_c_attribute(nodiscard
) == 202003L);
6 struct [[nodiscard
]] S1
{ // ok
9 struct [[nodiscard
, nodiscard
]] S2
{ // ok
12 struct [[nodiscard("Wrong")]] S3
{
16 struct S3
get_s3(void);
18 [[nodiscard
]] int f1(void);
19 enum [[nodiscard
]] E1
{ One
};
21 [[nodiscard
]] int i
; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
23 struct [[nodiscard
]] S4
{
26 struct S4
get_s(void);
28 enum [[nodiscard
]] E2
{ Two
};
31 [[nodiscard
]] int get_i(void);
34 get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
35 get_s3(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Wrong}}
36 get_i(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
37 get_e(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
39 // Okay, warnings are not encouraged
46 struct [[nodiscard
]] error_info
{
50 struct error_info
enable_missile_safety_mode(void);
51 void launch_missiles(void);
52 void test_missiles(void) {
53 enable_missile_safety_mode(); // expected-warning {{ignoring return value of function declared with 'nodiscard'}}