summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
diff options
context:
space:
mode:
authorFelix Berger <flx@google.com>2016-02-15 03:36:23 +0000
committerFelix Berger <flx@google.com>2016-02-15 03:36:23 +0000
commitf4fdc8aba00d8a8508af7ed86cab2dbc7f17ed08 (patch)
treed8a6cade498539472f7b6888e119df7657886e43 /clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
parent1429412fe355b947c14f6f5cb92d6fad728dfa65 (diff)
downloadbcm5719-llvm-f4fdc8aba00d8a8508af7ed86cab2dbc7f17ed08.tar.gz
bcm5719-llvm-f4fdc8aba00d8a8508af7ed86cab2dbc7f17ed08.zip
[clang-tidy] Only invoke ForRangeCopyCheck on expensive-to-copy types.
Summary: Fix oversight not checking the value of the Optional<bool> returned by isExpensiveToCopy(). Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17064 llvm-svn: 260870
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp b/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
index 88e277720fb..a293cfee760 100644
--- a/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp
@@ -135,7 +135,9 @@ bool ForRangeCopyCheck::handleConstValueCopy(const VarDecl &LoopVar,
} else if (!LoopVar.getType().isConstQualified()) {
return false;
}
- if (!type_traits::isExpensiveToCopy(LoopVar.getType(), Context))
+ llvm::Optional<bool> Expensive =
+ type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
+ if (!Expensive || !*Expensive)
return false;
auto Diagnostic =
diag(LoopVar.getLocation(),
@@ -150,8 +152,9 @@ bool ForRangeCopyCheck::handleConstValueCopy(const VarDecl &LoopVar,
bool ForRangeCopyCheck::handleCopyIsOnlyConstReferenced(
const VarDecl &LoopVar, const CXXForRangeStmt &ForRange,
ASTContext &Context) {
- if (LoopVar.getType().isConstQualified() ||
- !type_traits::isExpensiveToCopy(LoopVar.getType(), Context)) {
+ llvm::Optional<bool> Expensive =
+ type_traits::isExpensiveToCopy(LoopVar.getType(), Context);
+ if (LoopVar.getType().isConstQualified() || !Expensive || !*Expensive) {
return false;
}
// Collect all DeclRefExprs to the loop variable and all CallExprs and
OpenPOWER on IntegriCloud