[clang-tools-extra] e8b8f89 - [clang-tidy] Simplify braced init check
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 20 12:09:55 PST 2021
Author: Stephen Kelly
Date: 2021-02-20T20:09:13Z
New Revision: e8b8f896024620eb86bf924be73100d83c74c736
URL: https://github.com/llvm/llvm-project/commit/e8b8f896024620eb86bf924be73100d83c74c736
DIFF: https://github.com/llvm/llvm-project/commit/e8b8f896024620eb86bf924be73100d83c74c736.diff
LOG: [clang-tidy] Simplify braced init check
The normalization of matchers means that this now works in all language
modes.
Differential Revision: https://reviews.llvm.org/D96135
Added:
Modified:
clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
index 6dc91e91ffde..4c8b9571e4c7 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -23,21 +23,14 @@ void ReturnBracedInitListCheck::registerMatchers(MatchFinder *Finder) {
auto ConstructExpr =
cxxConstructExpr(
unless(anyOf(hasDeclaration(cxxConstructorDecl(isExplicit())),
- isListInitialization(), hasDescendant(initListExpr()),
- isInTemplateInstantiation())))
+ isListInitialization(), hasDescendant(initListExpr()))))
.bind("ctor");
- auto CtorAsArgument = materializeTemporaryExpr(anyOf(
- has(ConstructExpr), has(cxxFunctionalCastExpr(has(ConstructExpr)))));
-
Finder->addMatcher(
- traverse(TK_AsIs,
- functionDecl(
- isDefinition(), // Declarations don't have return statements.
- returns(unless(anyOf(builtinType(), autoType()))),
- hasDescendant(returnStmt(hasReturnValue(
- has(cxxConstructExpr(has(CtorAsArgument)))))))
- .bind("fn")),
+ returnStmt(hasReturnValue(ConstructExpr),
+ forFunction(functionDecl(returns(unless(anyOf(builtinType(),
+ autoType()))))
+ .bind("fn"))),
this);
}
diff --git a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
index 12bd694cd3ae..da863891bdee 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.h
@@ -29,6 +29,9 @@ class ReturnBracedInitListCheck : public ClangTidyCheck {
}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace modernize
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
index 29d81c6df1f0..4db1d49da2ea 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize-return-braced-init-list.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++14 %s modernize-return-braced-init-list %t
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-return-braced-init-list %t
namespace std {
typedef decltype(sizeof(int)) size_t;
More information about the cfe-commits
mailing list