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

Yihe Li via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 15 06:25:51 PST 2024


================
@@ -1616,22 +1616,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();
----------------
Mick235711 wrote:

Yes, that is definitely observable, as I presented in https://github.com/llvm/llvm-project/pull/112521#issuecomment-2417847257. This actually fixed an inconsistency bug between Clang and GCC/MSVC, with the latter two already always preferring the callee decl.

I will add a release note for this.

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


More information about the cfe-commits mailing list