33 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3struct [[nodiscard]] expected {};4 5typedef struct expected E;6 7[[nodiscard]] typedef int NI; // expected-warning {{'[[nodiscard]]' attribute ignored when applied to a typedef}}8typedef __attribute__((warn_unused_result)) int WUR;9 10@interface INTF11- (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@end21 22void 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 void30 [a h]; // no warning because attribute is ignored when applied to a typedef31 [a i]; // expected-warning {{ignoring return value of type 'WUR' declared with 'warn_unused_result' attribute}}32}33