[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 15 09:19:11 PDT 2024


================
@@ -302,27 +312,38 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
     if (const Decl *FD = CE->getCalleeDecl()) {
       if (ShouldSuppress)
         return;
-      if (FD->hasAttr<PureAttr>()) {
+      if (const auto *A = FD->getAttr<PureAttr>()) {
         Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure";
+        if (OffendingDecl && !OffendingDecl->getIdentifier()->getBuiltinID())
----------------
erichkeane wrote:

it won't be the 1st line IIRC, the built in location should have the location <builtin>, which makes sense.

I think this test is still sensible though.

https://github.com/llvm/llvm-project/pull/112289


More information about the cfe-commits mailing list