[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / c2x-nodiscard.c
blobcb33c0c242e7db9276a599655e0806f15a79fdc4
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
7 int i;
8 };
9 struct [[nodiscard, nodiscard]] S2 { // ok
10 int i;
12 struct [[nodiscard("Wrong")]] S3 {
13 int i;
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 {
24 int i;
26 struct S4 get_s(void);
28 enum [[nodiscard]] E2 { Two };
29 enum E2 get_e(void);
31 [[nodiscard]] int get_i(void);
33 void f2(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
40 (void)get_s();
41 (void)get_s3();
42 (void)get_i();
43 (void)get_e();
46 struct [[nodiscard]] error_info{
47 int i;
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'}}
54 launch_missiles();