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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6874dfce3aef: [clang-tidy] Fix bugprone-use-after-move when 
move is in noexcept operator (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

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
@@ -1270,4 +1270,32 @@
 C c;
   }
 };
+} // namespace PR33020
+
+namespace UnevalContext {
+struct Foo {};
+void noExcept() {
+  Foo Bar;
+  (void) noexcept(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
 }
+void sizeOf() {
+  Foo Bar;
+  (void)sizeof(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
+}
+void alignOf() {
+  Foo Bar;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  (void)alignof(Foo{std::move(Bar)});
+#pragma clang diagnostic pop
+  Foo Other{std::move(Bar)};
+}
+void typeId() {
+  Foo Bar;
+  // error: you need to include  before using the 'typeid' operator
+  // (void) typeid(Foo{std::move(Bar)}).name();
+  Foo Other{std::move(Bar)};
+}
+} // namespace UnevalContext
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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +98,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   
to(functionDecl(ast_matchers::isTemplateInstantiation());
+   to(functionDecl(ast_matchers::isTemplateInstantiation(),
+   hasAncestor(expr(hasUnevaluatedContext(;
 }
 
 UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)


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
@@ -1270,4 +1270,32 @@
 C c;
   }
 };
+} // namespace PR33020
+
+namespace UnevalContext {
+struct Foo {};
+void noExcept() {
+  Foo Bar;
+  (void) noexcept(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
 }
+void sizeOf() {
+  Foo Bar;
+  (void)sizeof(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
+}
+void alignOf() {
+  Foo Bar;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  (void)alignof(Foo{std::move(Bar)});
+#pragma clang diagnostic pop
+  Foo Other{std::move(Bar)};
+}
+void typeId() {
+  Foo Bar;
+  // error: you need to include  before using the 'typeid' operator
+  // (void) typeid(Foo{std::move(Bar)}).name();
+  Foo Other{std::move(Bar)};
+}
+} // namespace UnevalContext
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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto 

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

2020-01-27 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62249 tests passed, 0 failed 
and 816 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 240718.
njames93 added a comment.

- Remove artifacts of old dependent review


Repository:
  rG LLVM Github Monorepo

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

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
@@ -1270,4 +1270,32 @@
 C c;
   }
 };
+} // namespace PR33020
+
+namespace UnevalContext {
+struct Foo {};
+void noExcept() {
+  Foo Bar;
+  (void) noexcept(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
 }
+void sizeOf() {
+  Foo Bar;
+  (void)sizeof(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
+}
+void alignOf() {
+  Foo Bar;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  (void)alignof(Foo{std::move(Bar)});
+#pragma clang diagnostic pop
+  Foo Other{std::move(Bar)};
+}
+void typeId() {
+  Foo Bar;
+  // error: you need to include  before using the 'typeid' operator
+  // (void) typeid(Foo{std::move(Bar)}).name();
+  Foo Other{std::move(Bar)};
+}
+} // namespace UnevalContext
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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +98,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   
to(functionDecl(ast_matchers::isTemplateInstantiation());
+   to(functionDecl(ast_matchers::isTemplateInstantiation(),
+   hasAncestor(expr(hasUnevaluatedContext(;
 }
 
 UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)


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
@@ -1270,4 +1270,32 @@
 C c;
   }
 };
+} // namespace PR33020
+
+namespace UnevalContext {
+struct Foo {};
+void noExcept() {
+  Foo Bar;
+  (void) noexcept(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
 }
+void sizeOf() {
+  Foo Bar;
+  (void)sizeof(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
+}
+void alignOf() {
+  Foo Bar;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  (void)alignof(Foo{std::move(Bar)});
+#pragma clang diagnostic pop
+  Foo Other{std::move(Bar)};
+}
+void typeId() {
+  Foo Bar;
+  // error: you need to include  before using the 'typeid' operator
+  // (void) typeid(Foo{std::move(Bar)}).name();
+  Foo Other{std::move(Bar)};
+}
+} // namespace UnevalContext
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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return 

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

2020-01-27 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62213 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 240547.
njames93 added a comment.

- Fix nits in test cases


Repository:
  rG LLVM Github Monorepo

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

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
@@ -1270,4 +1270,32 @@
 C c;
   }
 };
+} // namespace PR33020
+
+namespace UnevalContext {
+struct Foo {};
+void noExcept() {
+  Foo Bar;
+  (void) noexcept(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
 }
+void sizeOf() {
+  Foo Bar;
+  (void)sizeof(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
+}
+void alignOf() {
+  Foo Bar;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  (void)alignof(Foo{std::move(Bar)});
+#pragma clang diagnostic pop
+  Foo Other{std::move(Bar)};
+}
+void typeId() {
+  Foo Bar;
+  // error: you need to include  before using the 'typeid' operator
+  // (void) typeid(Foo{std::move(Bar)}).name();
+  Foo Other{std::move(Bar)};
+}
+} // namespace UnevalContext
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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +98,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   
to(functionDecl(ast_matchers::isTemplateInstantiation());
+   to(functionDecl(ast_matchers::isTemplateInstantiation(),
+   hasAncestor(expr(hasUnevaluatedContext(;
 }
 
 UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)


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
@@ -1270,4 +1270,32 @@
 C c;
   }
 };
+} // namespace PR33020
+
+namespace UnevalContext {
+struct Foo {};
+void noExcept() {
+  Foo Bar;
+  (void) noexcept(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
 }
+void sizeOf() {
+  Foo Bar;
+  (void)sizeof(Foo{std::move(Bar)});
+  Foo Other{std::move(Bar)};
+}
+void alignOf() {
+  Foo Bar;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  (void)alignof(Foo{std::move(Bar)});
+#pragma clang diagnostic pop
+  Foo Other{std::move(Bar)};
+}
+void typeId() {
+  Foo Bar;
+  // error: you need to include  before using the 'typeid' operator
+  // (void) typeid(Foo{std::move(Bar)}).name();
+  Foo Other{std::move(Bar)};
+}
+} // namespace UnevalContext
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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// 

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

2020-01-27 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added a comment.
This revision is now accepted and ready to land.

LGTM with fixes to the test.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1276
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};

njames93 wrote:
> gribozavr2 wrote:
> > njames93 wrote:
> > > gribozavr2 wrote:
> > > > Is the macro a necessary part of this test? If not, can it be removed?
> > > I like to stick to the bug report as much as possible
> > This is not generally the policy in LLVM and Clang. We prefer minimal 
> > reproducers.
> I've kept it minimal, the REQUIRE definition is just to suppress other 
> warnings about unused expressions
Adding `(void)` should do the trick.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1279
+
+void foo() {
+  S s;

I'm not sure why `foo` and `otherUnenvaluated` are separate functions. If you 
want to separate them, I think it would make more sense to put each operator 
into a separate function then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62207 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62206 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 240512.
njames93 added a comment.

- Fix formatting


Repository:
  rG LLVM Github Monorepo

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

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,28 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+void otherUnevaluated(){
+  S s;
+  REQUIRE(sizeof(S{std::move(s)}) > 8);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  REQUIRE(alignof(S{std::move(s)}) > 8);
+#pragma clang diagnostic pop
+
+  // error: you need to include  before using the 'typeid' operator
+  // REQUIRE(typeid(S{std::move(s)}).name());
+
+  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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +98,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   
to(functionDecl(ast_matchers::isTemplateInstantiation());
+   to(functionDecl(ast_matchers::isTemplateInstantiation(),
+   hasAncestor(expr(hasUnevaluatedContext(;
 }
 
 UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)


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,28 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+void otherUnevaluated(){
+  S s;
+  REQUIRE(sizeof(S{std::move(s)}) > 8);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  REQUIRE(alignof(S{std::move(s)}) > 8);
+#pragma clang diagnostic pop
+
+  // error: you need to include  before using the 'typeid' operator
+  // REQUIRE(typeid(S{std::move(s)}).name());
+
+  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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,23 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext) {
+  if (isa(Node) || isa(Node))
+return true;
+  if (const auto *UnaryExpr = dyn_cast()) {
+switch (UnaryExpr->getKind()) {
+case UETT_SizeOf:
+case UETT_AlignOf:
+  return true;
+default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +98,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
- 

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

2020-01-27 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62207 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 240507.
njames93 added a comment.

- Elide braces


Repository:
  rG LLVM Github Monorepo

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

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,28 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+void otherUnevaluated(){
+  S s;
+  REQUIRE(sizeof(S{std::move(s)}) > 8);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  REQUIRE(alignof(S{std::move(s)}) > 8);
+#pragma clang diagnostic pop
+
+  // error: you need to include  before using the 'typeid' operator
+  // REQUIRE(typeid(S{std::move(s)}).name());
+
+  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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,21 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext){
+  if (isa(Node) || isa(Node)) return true;
+  if (const auto *UnaryExpr = dyn_cast()){
+switch (UnaryExpr->getKind()){
+  case UETT_SizeOf:
+  case UETT_AlignOf: return true;
+  default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +96,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   
to(functionDecl(ast_matchers::isTemplateInstantiation());
+   to(functionDecl(ast_matchers::isTemplateInstantiation(),
+   hasAncestor(expr(hasUnevaluatedContext(;
 }
 
 UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)


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,28 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+void otherUnevaluated(){
+  S s;
+  REQUIRE(sizeof(S{std::move(s)}) > 8);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  REQUIRE(alignof(S{std::move(s)}) > 8);
+#pragma clang diagnostic pop
+
+  // error: you need to include  before using the 'typeid' operator
+  // REQUIRE(typeid(S{std::move(s)}).name());
+
+  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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,21 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext){
+  if (isa(Node) || isa(Node)) return true;
+  if (const auto *UnaryExpr = dyn_cast()){
+switch (UnaryExpr->getKind()){
+  case UETT_SizeOf:
+  case UETT_AlignOf: return true;
+  default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast())
+return !TypeIDExpr->isPotentiallyEvaluated();
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +96,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   

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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 3 inline comments as done.
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1276
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};

gribozavr2 wrote:
> njames93 wrote:
> > gribozavr2 wrote:
> > > Is the macro a necessary part of this test? If not, can it be removed?
> > I like to stick to the bug report as much as possible
> This is not generally the policy in LLVM and Clang. We prefer minimal 
> reproducers.
I've kept it minimal, the REQUIRE definition is just to suppress other warnings 
about unused expressions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 240506.
njames93 added a comment.

- added more unevaluated context checks


Repository:
  rG LLVM Github Monorepo

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

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,28 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+void otherUnevaluated(){
+  S s;
+  REQUIRE(sizeof(S{std::move(s)}) > 8);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  REQUIRE(alignof(S{std::move(s)}) > 8);
+#pragma clang diagnostic pop
+
+  // error: you need to include  before using the 'typeid' operator
+  // REQUIRE(typeid(S{std::move(s)}).name());
+
+  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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,22 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext){
+  if (isa(Node) || isa(Node)) return true;
+  if (const auto *UnaryExpr = dyn_cast()){
+switch (UnaryExpr->getKind()){
+  case UETT_SizeOf:
+  case UETT_AlignOf: return true;
+  default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast()){
+return !TypeIDExpr->isPotentiallyEvaluated();
+  }
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +97,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),
hasAncestor(declRefExpr(
-   
to(functionDecl(ast_matchers::isTemplateInstantiation());
+   to(functionDecl(ast_matchers::isTemplateInstantiation(),
+   hasAncestor(expr(hasUnevaluatedContext(;
 }
 
 UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)


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,28 @@
   }
 };
 }
+
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};
+
+void foo() {
+  S s;
+  REQUIRE(noexcept(S{std::move(s)}));
+  S other{std::move(s)};
+}
+void otherUnevaluated(){
+  S s;
+  REQUIRE(sizeof(S{std::move(s)}) > 8);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
+  REQUIRE(alignof(S{std::move(s)}) > 8);
+#pragma clang diagnostic pop
+
+  // error: you need to include  before using the 'typeid' operator
+  // REQUIRE(typeid(S{std::move(s)}).name());
+
+  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,10 @@
 
 #include "UseAfterMoveCheck.h"
 
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Lex/Lexer.h"
 
@@ -23,6 +27,22 @@
 
 namespace {
 
+AST_MATCHER(Expr, hasUnevaluatedContext){
+  if (isa(Node) || isa(Node)) return true;
+  if (const auto *UnaryExpr = dyn_cast()){
+switch (UnaryExpr->getKind()){
+  case UETT_SizeOf:
+  case UETT_AlignOf: return true;
+  default:
+  return false;
+}
+  }
+  if (const auto *TypeIDExpr = dyn_cast()){
+return !TypeIDExpr->isPotentiallyEvaluated();
+  }
+  return false;
+}
+
 /// Contains information about a use-after-move.
 struct UseAfterMove {
   // The DeclRefExpr that constituted the use of the object.
@@ -77,7 +97,8 @@
 static StatementMatcher inDecltypeOrTemplateArg() {
   return anyOf(hasAncestor(typeLoc()),

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

2020-01-27 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1276
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};

njames93 wrote:
> gribozavr2 wrote:
> > Is the macro a necessary part of this test? If not, can it be removed?
> I like to stick to the bug report as much as possible
This is not generally the policy in LLVM and Clang. We prefer minimal 
reproducers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-27 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 2 inline comments as done.
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:387
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");

gribozavr2 wrote:
> Quuxplusone wrote:
> > What about `sizeof`, `alignof`, `requires`, `typeid`, and other such 
> > unevaluated contexts? Shouldn't there be a common way to spell "this 
> > expression is unevaluated"? (I don't know if there is or not.)
> +1 to adding handling and tests for other unevaluated contexts.
I think i can write a matcher that will detect that



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1276
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};

gribozavr2 wrote:
> Is the macro a necessary part of this test? If not, can it be removed?
I like to stick to the bug report as much as possible


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-26 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:387
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");

Quuxplusone wrote:
> What about `sizeof`, `alignof`, `requires`, `typeid`, and other such 
> unevaluated contexts? Shouldn't there be a common way to spell "this 
> expression is unevaluated"? (I don't know if there is or not.)
+1 to adding handling and tests for other unevaluated contexts.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp:1276
+namespace PR44667 {
+#define REQUIRE(expr) (void)(expr);
+struct S {};

Is the macro a necessary part of this test? If not, can it be removed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-26 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62199 tests passed, 0 failed 
and 815 were skipped.

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-26 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:387
+   unless(inDecltypeOrTemplateArg()),
+   unless(hasAncestor(cxxNoexceptExpr(
   .bind("call-move");

What about `sizeof`, `alignof`, `requires`, `typeid`, and other such 
unevaluated contexts? Shouldn't there be a common way to spell "this expression 
is unevaluated"? (I don't know if there is or not.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73441



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2020-01-26 Thread Nathan James via Phabricator via cfe-commits
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 
.


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(


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(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits