2020-02-02 01:40:07 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wall -Wrange-loop-bind-reference -Wno-unused -verify %s
|
2015-04-14 06:08:55 +08:00
|
|
|
// 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
|
2020-01-02 00:23:19 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
|
2015-04-14 06:08:55 +08:00
|
|
|
|
|
|
|
template <typename return_type>
|
|
|
|
struct Iterator {
|
|
|
|
return_type operator*();
|
|
|
|
Iterator operator++();
|
|
|
|
bool operator!=(const Iterator);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Container {
|
|
|
|
typedef Iterator<T> I;
|
|
|
|
|
|
|
|
I begin();
|
|
|
|
I end();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Foo {};
|
|
|
|
struct Bar {
|
2020-01-11 17:16:40 +08:00
|
|
|
// Small trivially copyable types do not show a warning when copied in a
|
|
|
|
// range-based for loop. This size ensures the object is not considered
|
|
|
|
// small.
|
|
|
|
char s[128];
|
2015-04-14 06:08:55 +08:00
|
|
|
Bar(Foo);
|
|
|
|
Bar(int);
|
|
|
|
operator int();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Testing notes:
|
|
|
|
// test0 checks that the full text of the warnings and notes is correct. The
|
|
|
|
// rest of the tests checks a smaller portion of the text.
|
|
|
|
// test1-6 are set in pairs, the odd numbers are the non-reference returning
|
|
|
|
// versions of the even numbers.
|
|
|
|
// test7-9 use an array instead of a range object
|
2016-08-25 00:37:21 +08:00
|
|
|
// tests use all four versions of the loop variable, const &T, const T, T&, and
|
2015-04-14 06:08:55 +08:00
|
|
|
// T. Versions producing errors and are commented out.
|
|
|
|
//
|
|
|
|
// Conversion chart:
|
|
|
|
// double <=> int
|
|
|
|
// int <=> Bar
|
|
|
|
// double => Bar
|
|
|
|
// Foo => Bar
|
|
|
|
//
|
|
|
|
// Conversions during tests:
|
|
|
|
// test1-2
|
|
|
|
// int => int
|
|
|
|
// int => double
|
|
|
|
// int => Bar
|
|
|
|
// test3-4
|
|
|
|
// Bar => Bar
|
|
|
|
// Bar => int
|
|
|
|
// test5-6
|
|
|
|
// Foo => Bar
|
|
|
|
// test7
|
|
|
|
// double => double
|
|
|
|
// double => int
|
|
|
|
// double => Bar
|
|
|
|
// test8
|
|
|
|
// Foo => Foo
|
|
|
|
// Foo => Bar
|
|
|
|
// test9
|
|
|
|
// Bar => Bar
|
|
|
|
// Bar => int
|
|
|
|
|
|
|
|
void test0() {
|
|
|
|
Container<int> int_non_ref_container;
|
|
|
|
Container<int&> int_container;
|
|
|
|
Container<Bar&> bar_container;
|
|
|
|
|
|
|
|
for (const int &x : int_non_ref_container) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{loop variable 'x' binds to a temporary value produced by a range of type 'Container<int>'}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{use non-reference type 'int'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
|
|
|
|
for (const double &x : int_container) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{loop variable 'x' of type 'const double &' binds to a temporary constructed from type 'int &'}}
|
|
|
|
// expected-note@-2 {{use non-reference type 'double' to make construction explicit or type 'const int &' to prevent copying}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:22}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
|
|
|
|
for (const Bar x : bar_container) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{loop variable 'x' creates a copy from type 'const Bar'}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{use reference type 'const Bar &' to prevent copying}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:18}:"&"
|
2015-04-14 06:08:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test1() {
|
|
|
|
Container<int> A;
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const int &&x : A) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int &x : A) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'int'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int x : A) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
2020-01-02 00:23:20 +08:00
|
|
|
for (int&& x : A) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (int &x : A) {}
|
|
|
|
// Binding error
|
|
|
|
for (int x : A) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const double &&x : A) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const double &x : A) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'double'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:22}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const double x : A) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
2020-01-02 00:23:20 +08:00
|
|
|
for (double &&x : A) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (double &x : A) {}
|
|
|
|
// Binding error
|
|
|
|
for (double x : A) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : A) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : A) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : A) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x : A) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (Bar &x : A) {}
|
|
|
|
// Binding error
|
|
|
|
for (Bar x : A) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
|
|
|
}
|
|
|
|
|
|
|
|
void test2() {
|
|
|
|
Container<int&> B;
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (const int &&x : B) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int &x : B) {}
|
|
|
|
// No warning, this reference is not a temporary
|
|
|
|
for (const int x : B) {}
|
|
|
|
// No warning on POD copy
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (int &x : B) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (int &x : B) {}
|
|
|
|
// No warning
|
|
|
|
for (int x : B) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const double &&x : B) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'double'{{.*}}'const int &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:23}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const double &x : B) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'double'{{.*}}'const int &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:22}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const double x : B) {}
|
2020-01-02 00:23:20 +08:00
|
|
|
for (double &&x : B) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'double'{{.*}}'const int &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:17}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (double &x : B) {}
|
|
|
|
// Binding error
|
|
|
|
for (double x : B) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : B) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : B) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : B) {}
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x : B) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (Bar &x : B) {}
|
|
|
|
// Binding error
|
|
|
|
for (Bar x : B) {}
|
|
|
|
// No warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test3() {
|
|
|
|
Container<Bar> C;
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : C) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : C) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x : C) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (Bar &x : C) {}
|
|
|
|
// Binding error
|
|
|
|
for (Bar x : C) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const int &&x : C) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'int'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int x : C) {}
|
|
|
|
// No warning, copy made
|
2020-01-02 00:23:20 +08:00
|
|
|
for (int &&x : C) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (int &x : C) {}
|
|
|
|
// Binding error
|
|
|
|
for (int x : C) {}
|
|
|
|
// No warning, copy made
|
|
|
|
}
|
|
|
|
|
|
|
|
void test4() {
|
|
|
|
Container<Bar&> D;
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (const Bar &&x : D) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : D) {}
|
|
|
|
// No warning, this reference is not a temporary
|
|
|
|
for (const Bar x : D) {}
|
|
|
|
// expected-warning@-1 {{creates a copy}}
|
|
|
|
// expected-note@-2 {{'const Bar &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:18}:"&"
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (Bar &&x : D) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (Bar &x : D) {}
|
|
|
|
// No warning
|
|
|
|
for (Bar x : D) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const int &&x : D) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int &x : D) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int x : D) {}
|
|
|
|
// No warning
|
2020-01-02 00:23:20 +08:00
|
|
|
for (int &&x : D) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (int &x : D) {}
|
|
|
|
// Binding error
|
|
|
|
for (int x : D) {}
|
|
|
|
// No warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test5() {
|
|
|
|
Container<Foo> E;
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : E) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : E) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : E) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x : E) {}
|
|
|
|
// No warning, rvalue-reference to the temporary
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (Bar &x : E) {}
|
|
|
|
// Binding error
|
|
|
|
for (Bar x : E) {}
|
|
|
|
// No warning, non-reference type indicates copy is made
|
|
|
|
}
|
|
|
|
|
|
|
|
void test6() {
|
|
|
|
Container<Foo&> F;
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : F) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : F) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : F) {}
|
|
|
|
// No warning.
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x : F) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (Bar &x : F) {}
|
|
|
|
// Binding error
|
|
|
|
for (Bar x : F) {}
|
|
|
|
// No warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test7() {
|
|
|
|
double G[2];
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (const double &&x : G) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const double &x : G) {}
|
|
|
|
// No warning
|
|
|
|
for (const double x : G) {}
|
|
|
|
// No warning on POD copy
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (double &&x : G) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (double &x : G) {}
|
|
|
|
// No warning
|
|
|
|
for (double x : G) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const int &&x : G) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const double &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int &x : G) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const double &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int x : G) {}
|
|
|
|
// No warning
|
2020-01-02 00:23:20 +08:00
|
|
|
for (int &&x : G) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const double &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (int &x : G) {}
|
|
|
|
// Binding error
|
|
|
|
for (int x : G) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : G) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const double &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : G) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const double &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : G) {}
|
|
|
|
// No warning
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x : G) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const double &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
|
|
|
//for (Bar &x : G) {}
|
2015-04-14 06:08:55 +08:00
|
|
|
// Binding error
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar x : G) {}
|
2015-04-14 06:08:55 +08:00
|
|
|
// No warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test8() {
|
|
|
|
Foo H[2];
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (const Foo &&x : H) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Foo &x : H) {}
|
|
|
|
// No warning
|
|
|
|
for (const Foo x : H) {}
|
|
|
|
// No warning on POD copy
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (Foo &&x : H) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (Foo &x : H) {}
|
|
|
|
// No warning
|
|
|
|
for (Foo x : H) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const Bar &&x : H) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : H) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar x : H) {}
|
|
|
|
// No warning
|
2020-01-02 00:23:20 +08:00
|
|
|
for (Bar &&x: H) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (Bar &x: H) {}
|
|
|
|
// Binding error
|
|
|
|
for (Bar x: H) {}
|
|
|
|
// No warning
|
|
|
|
}
|
|
|
|
|
|
|
|
void test9() {
|
|
|
|
Bar I[2] = {1,2};
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (const Bar &&x : I) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const Bar &x : I) {}
|
|
|
|
// No warning
|
|
|
|
for (const Bar x : I) {}
|
|
|
|
// expected-warning@-1 {{creates a copy}}
|
|
|
|
// expected-note@-2 {{'const Bar &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:18}:"&"
|
2020-01-02 00:23:20 +08:00
|
|
|
//for (Bar &&x : I) {}
|
|
|
|
// Binding error
|
2015-04-14 06:08:55 +08:00
|
|
|
for (Bar &x : I) {}
|
|
|
|
// No warning
|
|
|
|
for (Bar x : I) {}
|
|
|
|
// No warning
|
|
|
|
|
2020-01-02 00:23:20 +08:00
|
|
|
for (const int &&x : I) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int &x : I) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2015-04-14 06:08:55 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
for (const int x : I) {}
|
|
|
|
// No warning
|
2020-01-02 00:23:20 +08:00
|
|
|
for (int &&x : I) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary constructed from}}
|
2020-01-02 00:23:20 +08:00
|
|
|
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
|
2015-04-14 06:08:55 +08:00
|
|
|
//for (int &x : I) {}
|
|
|
|
// Binding error
|
|
|
|
for (int x : I) {}
|
|
|
|
// No warning
|
|
|
|
}
|
2020-01-02 00:23:19 +08:00
|
|
|
|
|
|
|
void test10() {
|
|
|
|
Container<Bar> C;
|
|
|
|
|
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
|
|
|
|
|
|
|
for (const Bar& x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:18}:""
|
|
|
|
|
|
|
|
for (const Bar & x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
|
|
|
|
|
|
|
|
for (const Bar&x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-02 00:23:19 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:18}:" "
|
|
|
|
}
|
2020-01-20 00:01:12 +08:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void test_template_function() {
|
|
|
|
// In a template instantiation the diagnostics should not be emitted for
|
|
|
|
// loops with dependent types.
|
|
|
|
Container<Bar> C;
|
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-20 00:01:12 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
|
|
|
|
|
|
|
|
Container<T> Dependent;
|
|
|
|
for (const T &x : Dependent) {}
|
|
|
|
}
|
|
|
|
template void test_template_function<Bar>();
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct test_template_struct {
|
|
|
|
static void static_member() {
|
|
|
|
Container<Bar> C;
|
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-20 00:01:12 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:21}:""
|
|
|
|
|
|
|
|
Container<T> Dependent;
|
|
|
|
for (const T &x : Dependent) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
void member() {
|
|
|
|
Container<Bar> C;
|
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-20 00:01:12 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:21}:""
|
|
|
|
|
|
|
|
Container<T> Dependent;
|
|
|
|
for (const T &x : Dependent) {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template struct test_template_struct<Bar>;
|
|
|
|
|
|
|
|
struct test_struct_with_templated_member {
|
|
|
|
void member() {
|
|
|
|
Container<Bar> C;
|
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-20 00:01:12 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:21}:""
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void template_member() {
|
|
|
|
Container<Bar> C;
|
|
|
|
for (const Bar &x : C) {}
|
[Sema] Reword -Wrange-loop-analysis warning messages
Summary:
The messages for two of the warnings are misleading:
* warn_for_range_const_reference_copy suggests that the initialization
of the loop variable results in a copy. But that's not always true,
we just know that some conversion happens, potentially invoking a
constructor or conversion operator. The constructor might copy, as in
the example that lead to this message [1], but it might also not.
However, the constructed object is bound to a reference, which is
potentially misleading, so we rewrite the message to emphasize that.
We also make sure that we print the reference type into the warning
message to clarify that this warning only appears when operator*
returns a reference.
* warn_for_range_variable_always_copy suggests that a reference type
loop variable initialized from a temporary "is always a copy". But
we don't know this, the range might just return temporary objects
which aren't copies of anything. (Assuming RVO a copy constructor
might never have been called.)
The message for warn_for_range_copy is a bit repetitive: the type of a
VarDecl and its initialization Expr are the same up to cv-qualifiers,
because Sema will insert implicit casts or constructor calls to make
them match.
[1] https://bugs.llvm.org/show_bug.cgi?id=32823
Reviewers: aaron.ballman, Mordante, rtrieu
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D75613
2020-03-06 21:56:47 +08:00
|
|
|
// expected-warning@-1 {{binds to a temporary value produced by a range}}
|
2020-01-20 00:01:12 +08:00
|
|
|
// expected-note@-2 {{'Bar'}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:20-[[@LINE-3]]:21}:""
|
|
|
|
|
|
|
|
Container<T> Dependent;
|
|
|
|
for (const T &x : Dependent) {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template void test_struct_with_templated_member::template_member<Bar>();
|
|
|
|
|
|
|
|
#define TEST_MACRO \
|
|
|
|
void test_macro() { \
|
|
|
|
Container<Bar> C; \
|
|
|
|
for (const Bar &x : C) {} \
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_MACRO
|