[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 18:27:24 PST 2024
================
@@ -1615,22 +1615,24 @@ QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const {
return FnType->getReturnType();
}
-const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
+std::pair<const NamedDecl *, const Attr *>
+CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
+ // If the callee is marked nodiscard, return that attribute
+ const Decl *D = getCalleeDecl();
+ if (const auto *A = D->getAttr<WarnUnusedResultAttr>())
----------------
shafik wrote:
This looks like an unconditional access of `D` but it is not obvious this is a correct assumption
https://github.com/llvm/llvm-project/pull/112521
More information about the cfe-commits
mailing list