[clang] [clang] [Sema] Enable nodiscard warnings for function pointers (PR #154250)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 19 00:14:17 PDT 2025


================
@@ -2794,6 +2794,16 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
         return true;
       }
     }
+    if (CE->hasUnusedResultAttr(Ctx)) {
----------------
Sirraide wrote:

I think we can simplify this by adjusting the `if` statement before this one instead of duplicating everything here. I.e. something like this:
```c++
const CallExpr *CE = cast<CallExpr>(this);
const Decl *FD = CE->getCalleeDecl();
bool PureOrConst = FD && (FD->hasAttr<PureAttr>() || FD->hasAttr<ConstAttr>());
if (CE->hasUnusedResultAttr(Ctx) || PureOrConst) {
    // ...
}
```
Then delete the inner `if` and just fold its body into the outer if.

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


More information about the cfe-commits mailing list