summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorMark de Wever <koraq@xs4all.nl>2020-01-01 17:23:20 +0100
committerMark de Wever <koraq@xs4all.nl>2020-01-01 20:02:18 +0100
commite5ab1e49f958cd8388bab617819ba78167e557d3 (patch)
tree72294366f36eede9f7c75016c636bac63b44805a /clang/lib/Sema/SemaStmt.cpp
parentf022a5a792fd39a4c33f49583d24d96c70177066 (diff)
downloadbcm5719-llvm-e5ab1e49f958cd8388bab617819ba78167e557d3.tar.gz
bcm5719-llvm-e5ab1e49f958cd8388bab617819ba78167e557d3.zip
Improve Wrange-loop-analyses for rvalue reference
The Wrange-loop-analyses warns if a copy is made. Suppress this warning when a temporary is bound to a rvalue reference. While fixing this issue also found a copy-paste error in test6, which is also fixed. Differential Revision: https://reviews.llvm.org/D71806
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 959adbf1c35..1e7cc503d8c 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2764,9 +2764,11 @@ static void DiagnoseForRangeReferenceVariableCopies(Sema &SemaRef,
SemaRef.Diag(VD->getBeginLoc(), diag::note_use_type_or_non_reference)
<< NonReferenceType << NewReferenceType << VD->getSourceRange()
<< FixItHint::CreateRemoval(VD->getTypeSpecEndLoc());
- } else {
+ } else if (!VariableType->isRValueReferenceType()) {
// The range always returns a copy, so a temporary is always created.
// Suggest removing the reference from the loop variable.
+ // If the type is a rvalue reference do not warn since that changes the
+ // semantic of the code.
SemaRef.Diag(VD->getLocation(), diag::warn_for_range_variable_always_copy)
<< VD << RangeInitType;
QualType NonReferenceType = VariableType.getNonReferenceType();
OpenPOWER on IntegriCloud