Debian Codegraph @

clang/test/SemaObjCXX/attr-nodiscard.mm

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2
3 template<class T>
4 struct [[nodiscard]] expected {};
5
6 using E = expected<int>;
7
8 using NI [[nodiscard]] = int; // expected-warning {{'[[nodiscard]]' attribute ignored when applied to a typedef}}
9 using WURI [[clang::warn_unused_result]] = int;
10
11 @interface INTF
12 - (int) a [[nodiscard]];
13 + (int) b [[nodiscard]];
14 - (expected<int>) c;
15 + (expected<int>) d;
16 - (E) e;
17 + (E) f;
18 - (void) g [[nodiscard]]; // expected-warning {{attribute 'nodiscard' cannot be applied to Objective-C method without return value}}
19 - (NI) h;
20 - (WURI) i;
21 @end
22
23 void foo(INTF *a) {
24 [a a]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
25 [INTF b]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26 [a c]; // expected-warning {{ignoring return value of type 'expected<int>' declared with 'nodiscard' attribute}}
27 [INTF d]; // expected-warning {{ignoring return value of type 'expected<int>' declared with 'nodiscard' attribute}}
28 [a e]; // expected-warning {{ignoring return value of type 'expected<int>' declared with 'nodiscard' attribute}}
29 [INTF f]; // expected-warning {{ignoring return value of type 'expected<int>' declared with 'nodiscard' attribute}}
30 [a g]; // no warning because g returns void
31 [a h]; // no warning because attribute is ignored
32 [a i]; // expected-warning {{ignoring return value of type 'WURI' declared with 'clang::warn_unused_result' attribute}}
33 }