[PATCH] D55949: Correctly handle function pointers returning a type marked nodiscard

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 21 12:57:08 PST 2018


aaron.ballman requested review of this revision.
aaron.ballman added a comment.

There's enough churn based on the review feedback that this should probably have a second round of review just to be sure.



================
Comment at: lib/AST/Expr.cpp:2281-2286
+      // If there is no FunctionDecl for the call, check the return type of the
+      // callee to see if it was declared with the WarnUnusedResult attribute.
+      if (!Func && !HasWarnUnusedResultAttr) {
+        if (const TagDecl *TD = CE->getCallReturnType(Ctx)->getAsTagDecl())
+          HasWarnUnusedResultAttr = TD->hasAttr<WarnUnusedResultAttr>();
+      }
----------------
erik.pilkington wrote:
> This duplicates some logic from FunctionDecl::hasUnusedResultAttr(), maybe we should move that member function to the CallExpr?
Good suggestion -- I think that cleans up the interface nicely.


================
Comment at: test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:51
+
+  one(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+  two(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
----------------
erik.pilkington wrote:
> This diagnostic should also probably be improved at some point, the function wasn't declared 'nodiscard', the type was.
Yeah, I noticed that as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55949/new/

https://reviews.llvm.org/D55949





More information about the cfe-commits mailing list