summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorMark de Wever <koraq@xs4all.nl>2020-01-19 17:01:12 +0100
committerHans Wennborg <hans@chromium.org>2020-01-23 20:04:04 +0100
commit318677e78def0023d210a29f4b3cf648e02f9fdc (patch)
tree22fc8c77bc996e54161f9efa5a896d864b9b2bf2 /clang/lib
parenta3982a59ce34039f63fff35c6c0562cf6fd5c771 (diff)
downloadbcm5719-llvm-318677e78def0023d210a29f4b3cf648e02f9fdc.tar.gz
bcm5719-llvm-318677e78def0023d210a29f4b3cf648e02f9fdc.zip
[Sema] Avoid Wrange-loop-analysis false positives
When Wrange-loop-analysis issues a diagnostic on a dependent type in a template the diagnostic may not be valid for all instantiations. Therefore the diagnostic is suppressed during the instantiation. Non dependent types still issue a diagnostic. The same can happen when using macros. Therefore the diagnostic is disabled for macros. Fixes https://bugs.llvm.org/show_bug.cgi?id=44556 Differential Revision: https://reviews.llvm.org/D73007 (cherry picked from commit 41fcd17250fa0526e4b7fd2c7df7721b0f79b683)
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index d6c3af9e84c..ff648100628 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2838,6 +2838,9 @@ static void DiagnoseForRangeConstVariableCopies(Sema &SemaRef,
/// Suggest "const foo &x" to prevent the copy.
static void DiagnoseForRangeVariableCopies(Sema &SemaRef,
const CXXForRangeStmt *ForStmt) {
+ if (SemaRef.inTemplateInstantiation())
+ return;
+
if (SemaRef.Diags.isIgnored(diag::warn_for_range_const_reference_copy,
ForStmt->getBeginLoc()) &&
SemaRef.Diags.isIgnored(diag::warn_for_range_variable_always_copy,
@@ -2860,6 +2863,9 @@ static void DiagnoseForRangeVariableCopies(Sema &SemaRef,
if (!InitExpr)
return;
+ if (InitExpr->getExprLoc().isMacroID())
+ return;
+
if (VariableType->isReferenceType()) {
DiagnoseForRangeReferenceVariableCopies(SemaRef, VD,
ForStmt->getRangeInit()->getType());
OpenPOWER on IntegriCloud