[clang] [clang] Improve diagnostic on [[nodiscard]] attribute (PR #112521)

Yihe Li via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 04:54:31 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>())
----------------
Mick235711 wrote:

Indeed, it seems I forgot to add a check for `nullptr`.
Will open a PR to fix this later today.

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


More information about the cfe-commits mailing list