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

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 20 14:13:08 PST 2018


erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

LGTM!



================
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>();
+      }
----------------
This duplicates some logic from FunctionDecl::hasUnusedResultAttr(), maybe we should move that member function to the CallExpr?


================
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}}
----------------
This diagnostic should also probably be improved at some point, the function wasn't declared 'nodiscard', the type was.


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

https://reviews.llvm.org/D55949





More information about the cfe-commits mailing list