f(); // warn [b f]; // no warn } Clang 20 correctly diagnoses t...">

Should diagnose discard of Objective-C++ method returning nodiscard type (original) (raw)

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