mirrored from git://gcc.gnu.org/git/gcc.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++: non-dependent assignment checking [PR63198, PR18474]
This patch makes us recognize and check non-dependent simple assigments ahead of time, like we already do for compound assignments. This means the templated representation of such assignments will now usually have an implicit INDIRECT_REF (due to the reference return type), which the -Wparentheses code needs to handle. As a drive-by improvement, this patch also makes maybe_convert_cond issue -Wparentheses warnings ahead of time, and removes a seemingly unnecessary suppress_warning call in build_x_modify_expr. On the libstdc++ side, some tests were attempting to modify a data member from a uninstantiated const member function, which this patch minimally fixes by making the data member mutable. PR c++/63198 PR c++/18474 gcc/cp/ChangeLog: * semantics.cc (maybe_convert_cond): Look through implicit INDIRECT_REF when deciding whether to issue a -Wparentheses warning, and consider templated assignment expressions as well. (finish_parenthesized_expr): Look through implicit INDIRECT_REF when suppressing -Wparentheses warning. * typeck.cc (build_x_modify_expr): Check simple assignments ahead time too, not just compound assignments. Give the second operand of MODOP_EXPR a non-null type so that it's not considered always instantiation-dependent. Don't call suppress_warning. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/static_assert15.C: Expect diagnostic for non-constant static_assert condition. * g++.dg/expr/unary2.C: Remove xfails. * g++.dg/template/init7.C: Make initializer type-dependent to preserve intent of test. * g++.dg/template/recurse3.C: Likewise for the erroneous statement. * g++.dg/template/non-dependent26.C: New test. * g++.dg/warn/Wparentheses-32.C: New test. libstdc++-v3/ChangeLog: * testsuite/26_numerics/random/discard_block_engine/cons/seed_seq2.cc: Make data member seed_seq::called mutable. * testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq2.cc: Likewise. * testsuite/26_numerics/random/linear_congruential_engine/cons/seed_seq2.cc: Likewise. * testsuite/26_numerics/random/mersenne_twister_engine/cons/seed_seq2.cc: Likewise. * testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq2.cc: Likewise. * testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed_seq2.cc: Likewise. * testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq2.cc: Likewise.
- Loading branch information
Patrick Palka
committed
Sep 18, 2023
1 parent
a6ac1fc
commit 6e92a6a
Showing
15 changed files
with
100 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Verify non-dependent assignment expressions are recognized as such | ||
// and are checked ahead of time. | ||
// PR c++/63198 | ||
// { dg-do compile { target c++11 } } | ||
|
||
struct X { using t1 = int; }; | ||
struct Y { X operator=(const Y&); } y; | ||
template<class T> void f1(decltype(y = y)::t1); | ||
|
||
int n; | ||
template<class T> void f2(decltype(n = n)::t1); // { dg-error "not a class" } | ||
template<class T> void f3(decltype(n += n)::t1); // { dg-error "not a class" } | ||
|
||
template<class T> | ||
void g() { | ||
const int n; | ||
n = 42; // { dg-error "read-only" } | ||
|
||
const X x; | ||
x = {}; // { dg-error "no match" } | ||
|
||
const Y y; | ||
y = {}; // { dg-error "no match" } | ||
Y{} = X{}; // { dg-error "no match" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// PR c++/44609 | ||
// { dg-options -ftemplate-depth=10 } | ||
|
||
template<int N> | ||
template<class T, int N> | ||
void f() | ||
{ | ||
0 = 0; // { dg-error "lvalue required" } | ||
f<N+1>(); // { dg-bogus "instantiation depth" } | ||
T(0) = 0; // { dg-error "lvalue required" } | ||
f<T, N+1>(); // { dg-bogus "instantiation depth" } | ||
} | ||
|
||
int main() | ||
{ | ||
f<0>(); | ||
f<int, 0>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Verify we issue -Wparentheses warnings at template definition time | ||
// (for suitable non-dependent expressions). | ||
// { dg-additional-options "-Wparentheses" } | ||
|
||
struct X { operator bool(); }; | ||
struct Y { Y& operator=(const Y&); operator bool(); }; | ||
struct Z { int m; operator bool(); }; | ||
|
||
template<class T> | ||
void f() { | ||
int n, m; | ||
if (n = m) { } // { dg-warning "parentheses" } | ||
|
||
X x1, x2; | ||
if (x1 = x2) { } // { dg-warning "parentheses" } | ||
|
||
Y y1, y2; | ||
if (y1 = y2) { } // { dg-warning "parentheses" } | ||
|
||
Z z1, z2; | ||
if (z1 = z2) { } // { dg-warning "parentheses" } | ||
|
||
bool b; | ||
b = m = n; // { dg-warning "parentheses" "" { xfail *-*-* } } | ||
b = x1 = x2; // { dg-warning "parentheses" "" { xfail *-*-* } } | ||
b = y1 = y2; // { dg-warning "parentheses" "" { xfail *-*-* } } | ||
b = z1 = z2; // { dg-warning "parentheses" "" { xfail *-*-* } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters