34 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3template<class T>4struct [[nodiscard]] expected {};5 6using E = expected<int>;7 8using NI [[nodiscard]] = int; // expected-warning {{'[[nodiscard]]' attribute ignored when applied to a typedef}}9using WURI [[clang::warn_unused_result]] = int;10 11@interface INTF12- (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@end22 23void 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 void31 [a h]; // no warning because attribute is ignored32 [a i]; // expected-warning {{ignoring return value of type 'WURI' declared with 'clang::warn_unused_result' attribute}}33}34