diff options
author | Mark de Wever <koraq@xs4all.nl> | 2020-02-01 18:40:07 +0100 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-02-03 12:40:40 +0100 |
commit | 72e9e378c545aadb213e95892d50aa0b1248e018 (patch) | |
tree | fe8b49223c1b888bd3308f67d9f9b6acea7d1296 | |
parent | e11d70cfe7e2a8537eb774ed1780e9ecd1aa90a0 (diff) | |
download | bcm5719-llvm-72e9e378c545aadb213e95892d50aa0b1248e018.tar.gz bcm5719-llvm-72e9e378c545aadb213e95892d50aa0b1248e018.zip |
[Sema] Remove a -Wrange warning from -Wall
During the review of D73007 Aaron Puchert mentioned
`warn_for_range_variable_always_copy` shouldn't be part of -Wall since
some coding styles require `for(const auto &bar : bars)`. This warning
would cause false positives for these users. Based on Aaron's proposal
refactored the warnings:
* -Wrange-loop-construct warns about possibly unintended constructor
calls. This is part of -Wall. It contains
* warn_for_range_copy: loop variable A of type B creates a copy from
type C
* warn_for_range_const_reference_copy: loop variable A is initialized
with a value of a different type resulting in a copy
* -Wrange-loop-bind-reference warns about misleading use of reference
types. This is not part of -Wall. It contains
* warn_for_range_variable_always_copy: loop variable A is always a copy
because the range of type B does not return a reference
Differential Revision: https://reviews.llvm.org/D73434
(cherry picked from commit c03349e40f21f0375278138992a32694a99c830e)
-rw-r--r-- | clang/include/clang/Basic/DiagnosticGroups.td | 8 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 | ||||
-rw-r--r-- | clang/test/Misc/warning-wall.c | 5 | ||||
-rw-r--r-- | clang/test/SemaCXX/warn-range-loop-analysis.cpp | 2 |
4 files changed, 12 insertions, 9 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 6e89fd91f2f..5ad07915d2f 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -384,7 +384,10 @@ def GNULabelsAsValue : DiagGroup<"gnu-label-as-value">; def LiteralRange : DiagGroup<"literal-range">; def LocalTypeTemplateArgs : DiagGroup<"local-type-template-args", [CXX98CompatLocalTypeTemplateArgs]>; -def RangeLoopAnalysis : DiagGroup<"range-loop-analysis">; +def RangeLoopConstruct : DiagGroup<"range-loop-construct">; +def RangeLoopBindReference : DiagGroup<"range-loop-bind-reference">; +def RangeLoopAnalysis : DiagGroup<"range-loop-analysis", + [RangeLoopConstruct, RangeLoopBindReference]>; def ForLoopAnalysis : DiagGroup<"for-loop-analysis">; def LoopAnalysis : DiagGroup<"loop-analysis", [ForLoopAnalysis, RangeLoopAnalysis]>; @@ -858,14 +861,15 @@ def Most : DiagGroup<"most", [ Comment, DeleteNonVirtualDtor, Format, + ForLoopAnalysis, Implicit, InfiniteRecursion, IntInBoolContext, - LoopAnalysis, MismatchedTags, MissingBraces, Move, MultiChar, + RangeLoopConstruct, Reorder, ReturnType, SelfAssignment, diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5608e2064b2..ecf959b9077 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2378,17 +2378,17 @@ def warn_for_range_const_reference_copy : Warning< "loop variable %0 " "%diff{has type $ but is initialized with type $" "| is initialized with a value of a different type}1,2 resulting in a copy">, - InGroup<RangeLoopAnalysis>, DefaultIgnore; + InGroup<RangeLoopConstruct>, DefaultIgnore; def note_use_type_or_non_reference : Note< "use non-reference type %0 to keep the copy or type %1 to prevent copying">; def warn_for_range_variable_always_copy : Warning< "loop variable %0 is always a copy because the range of type %1 does not " "return a reference">, - InGroup<RangeLoopAnalysis>, DefaultIgnore; + InGroup<RangeLoopBindReference>, DefaultIgnore; def note_use_non_reference_type : Note<"use non-reference type %0">; def warn_for_range_copy : Warning< "loop variable %0 of type %1 creates a copy from type %2">, - InGroup<RangeLoopAnalysis>, DefaultIgnore; + InGroup<RangeLoopConstruct>, DefaultIgnore; def note_use_reference_type : Note<"use reference type %0 to prevent copying">; def err_objc_for_range_init_stmt : Error< "initialization statement is not supported when iterating over Objective-C " diff --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c index a98054e7589..737ed76859c 100644 --- a/clang/test/Misc/warning-wall.c +++ b/clang/test/Misc/warning-wall.c @@ -15,14 +15,12 @@ CHECK-NEXT: -Wnonnull CHECK-NEXT: -Wformat-security CHECK-NEXT: -Wformat-y2k CHECK-NEXT: -Wformat-invalid-specifier +CHECK-NEXT: -Wfor-loop-analysis CHECK-NEXT: -Wimplicit CHECK-NEXT: -Wimplicit-function-declaration CHECK-NEXT: -Wimplicit-int CHECK-NEXT: -Winfinite-recursion CHECK-NEXT: -Wint-in-bool-context -CHECK-NEXT: -Wloop-analysis -CHECK-NEXT: -Wfor-loop-analysis -CHECK-NEXT: -Wrange-loop-analysis CHECK-NEXT: -Wmismatched-tags CHECK-NEXT: -Wmissing-braces CHECK-NEXT: -Wmove @@ -31,6 +29,7 @@ CHECK-NEXT: -Wredundant-move CHECK-NEXT: -Wreturn-std-move CHECK-NEXT: -Wself-move CHECK-NEXT: -Wmultichar +CHECK-NEXT: -Wrange-loop-construct CHECK-NEXT: -Wreorder CHECK-NEXT: -Wreorder-ctor CHECK-NEXT: -Wreorder-init-list diff --git a/clang/test/SemaCXX/warn-range-loop-analysis.cpp b/clang/test/SemaCXX/warn-range-loop-analysis.cpp index 951844c953e..8331e6088b6 100644 --- a/clang/test/SemaCXX/warn-range-loop-analysis.cpp +++ b/clang/test/SemaCXX/warn-range-loop-analysis.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wall -Wno-unused -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wall -Wrange-loop-bind-reference -Wno-unused -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wrange-loop-analysis -verify %s // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s |