[PATCH] D97577: [clang-tidy] performance-for-range-copy: Don't trigger on implicit type conversions.
Felix Berger via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 26 13:37:13 PST 2021
flx updated this revision to Diff 326792.
flx added a comment.
Remove include.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97577/new/
https://reviews.llvm.org/D97577
Files:
clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp
@@ -60,13 +60,13 @@
void negativeUserDefinedConversion() {
Convertible C[0];
- for (const S &S1 : C) {
+ for (const S S1 : C) {
}
}
void negativeImplicitConstructorConversion() {
ConstructorConvertible C[0];
- for (const S &S1 : C) {
+ for (const S S1 : C) {
}
}
Index: clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
@@ -12,6 +12,7 @@
#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "../utils/TypeTraits.h"
+#include "third_party/llvm/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
#include "clang/Basic/Diagnostic.h"
@@ -45,10 +46,14 @@
hasOverloadedOperatorName("*"),
callee(
cxxMethodDecl(returns(unless(hasCanonicalType(referenceType()))))));
+ auto NotConstructedByCopy = cxxConstructExpr(
+ hasDeclaration(cxxConstructorDecl(unless(isCopyConstructor()))));
+ auto ConstructedByConversion = cxxMemberCallExpr(callee(cxxConversionDecl()));
auto LoopVar =
varDecl(HasReferenceOrPointerTypeOrIsAllowed,
- unless(hasInitializer(expr(hasDescendant(expr(anyOf(
- materializeTemporaryExpr(), IteratorReturnsValueType)))))));
+ unless(hasInitializer(expr(hasDescendant(expr(
+ anyOf(materializeTemporaryExpr(), IteratorReturnsValueType,
+ NotConstructedByCopy, ConstructedByConversion)))))));
Finder->addMatcher(
traverse(TK_AsIs,
cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97577.326792.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210226/5ea6a1cc/attachment.bin>
More information about the cfe-commits
mailing list