Skip to content

Should diagnose discard of Objective-C++ method returning nodiscard type #141504

@halbi2

Description

@halbi2
struct [[nodiscard("Expected")]] expected {};

struct A {
  expected f();
};
@interface B
  -(expected) f;
@end

void test(A* a, B* b) {
  a->f();  // warn
  [b f];  // no warn
}

Clang 20 correctly diagnoses the discarded result in a->f() but erroneously does not diagnose the discarded result in [b f].

https://godbolt.org/z/Gvx94Kcja

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerobjective-c++

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions