1 // RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s 2 3 struct [[nodiscard]] S1 { // ok 4 int i; 5 }; 6 struct [[nodiscard, nodiscard]] S2 { // ok 7 int i; 8 }; 9 struct [[nodiscard("Wrong")]] S3 { // FIXME: may need an extension warning. 10 int i; 11 }; 12 13 struct S3 get_s3(void); 14 15 [[nodiscard]] int f1(void); 16 enum [[nodiscard]] E1 { One }; 17 18 [[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}} 19 20 struct [[nodiscard]] S4 { 21 int i; 22 }; 23 struct S4 get_s(void); 24 25 enum [[nodiscard]] E2 { Two }; 26 enum E2 get_e(void); 27 28 [[nodiscard]] int get_i(); 29 f2(void)30void f2(void) { 31 get_s(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 32 get_s3(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute: Wrong}} 33 get_i(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 34 get_e(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 35 36 // Okay, warnings are not encouraged 37 (void)get_s(); 38 (void)get_s3(); 39 (void)get_i(); 40 (void)get_e(); 41 } 42 43 struct [[nodiscard]] error_info{ 44 int i; 45 }; 46 47 struct error_info enable_missile_safety_mode(void); 48 void launch_missiles(void); test_missiles(void)49void test_missiles(void) { 50 enable_missile_safety_mode(); // expected-warning {{ignoring return value of function declared with 'nodiscard'}} 51 launch_missiles(); 52 } 53 54