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