[PATCH] D73441: [clang-tidy] Fix bugprone-use-after-move when move is in noexcept operator

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 26 17:37:45 PST 2020


njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, JonasToth, hokein, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Fixes noexcept operator misinterpreted as being evaluated <https://bugs.llvm.org/show_bug.cgi?id=44667>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73441

Files:
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -1271,3 +1271,14 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+} // namespace PR44667
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -382,7 +383,8 @@
                hasArgument(0, declRefExpr().bind("arg")),
                anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
                      hasAncestor(functionDecl().bind("containing-func"))),
-               unless(inDecltypeOrTemplateArg()))
+               unless(inDecltypeOrTemplateArg()),
+               unless(hasAncestor(cxxNoexceptExpr())))
           .bind("call-move");
 
   Finder->addMatcher(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73441.240458.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200127/8bfb3c3b/attachment-0001.bin>


More information about the cfe-commits mailing list