[PATCH] D32207: Corrrect warn_unused_result attribute

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 06:37:50 PDT 2017


aaron.ballman added inline comments.


================
Comment at: lib/AST/Decl.cpp:3007
     const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl();
-    const auto *MD = dyn_cast<CXXMethodDecl>(this);
-    if (Ret && !(MD && MD->getCorrespondingMethodInClass(Ret, true))) {
+    auto OpCode = getOverloadedOperator();
+    bool IsPostfix =
----------------
Please don't use `auto` here.


================
Comment at: lib/AST/Decl.cpp:3010
+        (OpCode == OO_PlusPlus || OpCode == OO_MinusMinus) &&
+        (this->getNumParams() + (isa<CXXMethodDecl>(this) ? 1 : 0)) == 2;
+    if (Ret && !IsPostfix) {
----------------
CXXMethodDecl represents a static or instance method, so I'm not certain this logic is quite correct.


================
Comment at: test/SemaCXX/warn-unused-result.cpp:166
+// are special-cased to not warn for return-type due to ubiquitousness.
+struct[[clang::warn_unused_result]] S {
+  S DoThing() { return {}; };
----------------
Can you also add a test with [[nodiscard]] and verify that the uses of increment/decrement *are* diagnosed?


https://reviews.llvm.org/D32207





More information about the cfe-commits mailing list