From 20a1e5b8c856e019b86b7e4990bad9dcb04d0e35 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 14 Sep 2016 17:46:59 +0000 Subject: [PATCH] typeck.c (cp_build_unary_op): Diagnose incrementing boolean expressions. * typeck.c (cp_build_unary_op): Diagnose incrementing boolean expressions. Tweak an error message. * c-c++-common/gomp/atomic-12.c: Use -Wno-deprecated. * c-c++-common/gomp/atomic-13.c: Likewise. * c-c++-common/gomp/atomic-14.c: Likewise. * g++.dg/cpp1y/lambda-init11.C: Remove invalid code. * g++.dg/cpp1z/bool-increment1.C: New test. * c-c++-common/pr60439.c: Add dg-warning. * g++.dg/expr/bitfield4.C: Likewise. * g++.dg/expr/bitfield5.C: Likewise. * g++.dg/expr/bitfield6.C: Likewise. * g++.dg/expr/bool1.C: Likewise. * g++.dg/expr/bool3.C: Likewise. * g++.dg/expr/lval3.C: Likewise. * g++.dg/expr/lval4.C: Likewise. * g++.old-deja/g++.jason/bool5.C: Likewise. * g++.dg/expr/bitfield3.C: Adjust dg-error. * g++.dg/other/error18.C: Likewise. * g++.dg/gomp/atomic-14.C: Likewise. libgomp/ * testsuite/libgomp.c++/atomic-3.C: Use -Wno-deprecated. libstdc++-v3/ * testsuite/23_containers/vector/debug/insert6_neg.cc: Use -Wno-deprecated. From-SVN: r240141 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck.c | 22 ++++++++++++++++--- gcc/testsuite/ChangeLog | 20 +++++++++++++++++ gcc/testsuite/c-c++-common/gomp/atomic-12.c | 2 +- gcc/testsuite/c-c++-common/gomp/atomic-13.c | 2 +- gcc/testsuite/c-c++-common/gomp/atomic-14.c | 2 +- gcc/testsuite/c-c++-common/pr60439.c | 1 + gcc/testsuite/g++.dg/cpp1y/lambda-init11.C | 1 - gcc/testsuite/g++.dg/cpp1z/bool-increment1.C | 14 ++++++++++++ gcc/testsuite/g++.dg/expr/bitfield3.C | 4 ++-- gcc/testsuite/g++.dg/expr/bitfield4.C | 4 ++-- gcc/testsuite/g++.dg/expr/bitfield5.C | 4 ++-- gcc/testsuite/g++.dg/expr/bitfield6.C | 2 +- gcc/testsuite/g++.dg/expr/bool1.C | 4 ++-- gcc/testsuite/g++.dg/expr/bool3.C | 4 ++-- gcc/testsuite/g++.dg/expr/lval3.C | 1 + gcc/testsuite/g++.dg/expr/lval4.C | 1 + gcc/testsuite/g++.dg/gomp/atomic-14.C | 8 +++---- gcc/testsuite/g++.dg/other/error18.C | 2 +- gcc/testsuite/g++.old-deja/g++.jason/bool5.C | 4 ++-- libgomp/ChangeLog | 4 ++++ libgomp/testsuite/libgomp.c++/atomic-3.C | 1 + libstdc++-v3/ChangeLog | 5 +++++ .../23_containers/vector/debug/insert6_neg.cc | 1 + 24 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/bool-increment1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index df4655ec916..001479c8b5e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-09-14 Marek Polacek + + * typeck.c (cp_build_unary_op): Diagnose incrementing boolean + expressions. Tweak an error message. + 2016-09-14 Marek Polacek * cp-tree.h (cp_build_unary_op): Change nonconvert parameter type to diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c51d6d0b0df..c53a85a16e0 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6029,16 +6029,32 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert, complain)) return error_mark_node; - /* Forbid using -- on `bool'. */ + /* Forbid using -- or ++ in C++17 on `bool'. */ if (TREE_CODE (declared_type) == BOOLEAN_TYPE) { if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR) { if (complain & tf_error) - error ("invalid use of Boolean expression as operand " - "to %"); + error ("use of an operand of type %qT in % " + "is forbidden", boolean_type_node); return error_mark_node; } + else + { + if (cxx_dialect >= cxx1z) + { + if (complain & tf_error) + error ("use of an operand of type %qT in " + "% is forbidden in C++1z", + boolean_type_node); + return error_mark_node; + } + /* Otherwise, [depr.incr.bool] says this is deprecated. */ + else if (!in_system_header_at (input_location)) + warning (OPT_Wdeprecated, "use of an operand of type %qT " + "in % is deprecated", + boolean_type_node); + } val = boolean_increment (code, arg); } else if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e394dcd92f5..dc55a3d8cd2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,23 @@ +2016-09-14 Marek Polacek + + * c-c++-common/gomp/atomic-12.c: Use -Wno-deprecated. + * c-c++-common/gomp/atomic-13.c: Likewise. + * c-c++-common/gomp/atomic-14.c: Likewise. + * g++.dg/cpp1y/lambda-init11.C: Remove invalid code. + * g++.dg/cpp1z/bool-increment1.C: New test. + * c-c++-common/pr60439.c: Add dg-warning. + * g++.dg/expr/bitfield4.C: Likewise. + * g++.dg/expr/bitfield5.C: Likewise. + * g++.dg/expr/bitfield6.C: Likewise. + * g++.dg/expr/bool1.C: Likewise. + * g++.dg/expr/bool3.C: Likewise. + * g++.dg/expr/lval3.C: Likewise. + * g++.dg/expr/lval4.C: Likewise. + * g++.old-deja/g++.jason/bool5.C: Likewise. + * g++.dg/expr/bitfield3.C: Adjust dg-error. + * g++.dg/other/error18.C: Likewise. + * g++.dg/gomp/atomic-14.C: Likewise. + 2016-09-14 Nathan Sidwell PR c++/77539 diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-12.c b/gcc/testsuite/c-c++-common/gomp/atomic-12.c index 145e4201642..e9ca6503cfe 100644 --- a/gcc/testsuite/c-c++-common/gomp/atomic-12.c +++ b/gcc/testsuite/c-c++-common/gomp/atomic-12.c @@ -1,6 +1,6 @@ /* PR middle-end/45423 */ /* { dg-do compile } */ -/* { dg-options "-fopenmp -fdump-tree-gimple -g0" } */ +/* { dg-options "-fopenmp -fdump-tree-gimple -g0 -Wno-deprecated" } */ /* atomicvar should never be referenced in between the barrier and following #pragma omp atomic_load. */ /* { dg-final { scan-tree-dump-not "barrier\[^#\]*atomicvar" "gimple" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-13.c b/gcc/testsuite/c-c++-common/gomp/atomic-13.c index 2452035da5b..7f4afcf63ad 100644 --- a/gcc/testsuite/c-c++-common/gomp/atomic-13.c +++ b/gcc/testsuite/c-c++-common/gomp/atomic-13.c @@ -1,6 +1,6 @@ /* PR middle-end/45423 */ /* { dg-do compile } */ -/* { dg-options "-fopenmp -fdump-tree-gimple -g0 -O2" } */ +/* { dg-options "-fopenmp -fdump-tree-gimple -g0 -O2 -Wno-deprecated" } */ /* atomicvar should never be referenced in between the barrier and following #pragma omp atomic_load. */ /* { dg-final { scan-tree-dump-not "barrier\[^#\]*atomicvar" "gimple" } } */ diff --git a/gcc/testsuite/c-c++-common/gomp/atomic-14.c b/gcc/testsuite/c-c++-common/gomp/atomic-14.c index f8fc9d87257..7e2345387d4 100644 --- a/gcc/testsuite/c-c++-common/gomp/atomic-14.c +++ b/gcc/testsuite/c-c++-common/gomp/atomic-14.c @@ -1,6 +1,6 @@ /* PR middle-end/45423 */ /* { dg-do compile } */ -/* { dg-options "-fopenmp" } */ +/* { dg-options "-fopenmp -Wno-deprecated" } */ #ifdef __cplusplus bool *baz (); diff --git a/gcc/testsuite/c-c++-common/pr60439.c b/gcc/testsuite/c-c++-common/pr60439.c index 68bd33c22cb..71b397a1c7d 100644 --- a/gcc/testsuite/c-c++-common/pr60439.c +++ b/gcc/testsuite/c-c++-common/pr60439.c @@ -132,6 +132,7 @@ f6 (bool b) break; } switch (b++) /* { dg-warning "switch condition has" } */ + /* { dg-warning "is deprecated" "" { target c++ } 134 } */ { case 3: break; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init11.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init11.C index f7525d8664a..4d434cd9ca0 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-init11.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init11.C @@ -16,5 +16,4 @@ int main(){ foo(3.14f); foo(0); foo('a'); - foo(false); } diff --git a/gcc/testsuite/g++.dg/cpp1z/bool-increment1.C b/gcc/testsuite/g++.dg/cpp1z/bool-increment1.C new file mode 100644 index 00000000000..ae2dcf9f391 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/bool-increment1.C @@ -0,0 +1,14 @@ +// { dg-options -std=c++1z } + +int +fn (bool b) +{ + int r = 0; + + r += b++; // { dg-error "use of an operand of type .bool. in .operator\\+\\+. is forbidden in" } + r += ++b; // { dg-error "use of an operand of type .bool. in .operator\\+\\+. is forbidden in" } + r += b--; // { dg-error "use of an operand of type .bool. in .operator--. is forbidden" } + r += --b; // { dg-error "use of an operand of type .bool. in .operator--. is forbidden" } + + return r; +} diff --git a/gcc/testsuite/g++.dg/expr/bitfield3.C b/gcc/testsuite/g++.dg/expr/bitfield3.C index 3221263a906..3f30337c2db 100644 --- a/gcc/testsuite/g++.dg/expr/bitfield3.C +++ b/gcc/testsuite/g++.dg/expr/bitfield3.C @@ -7,6 +7,6 @@ struct S { S s; void f() { - s.x--; // { dg-error "Boolean expression" } - --s.x; // { dg-error "Boolean expression" } + s.x--; // { dg-error "use of an operand of type .bool." } + --s.x; // { dg-error "use of an operand of type .bool." } } diff --git a/gcc/testsuite/g++.dg/expr/bitfield4.C b/gcc/testsuite/g++.dg/expr/bitfield4.C index d824964e187..7fae086b857 100644 --- a/gcc/testsuite/g++.dg/expr/bitfield4.C +++ b/gcc/testsuite/g++.dg/expr/bitfield4.C @@ -14,6 +14,6 @@ template <> void f(bool) {} int main() { - f(s.x++); - f(++s.x); + f(s.x++); // { dg-warning "deprecated" } + f(++s.x); // { dg-warning "deprecated" } } diff --git a/gcc/testsuite/g++.dg/expr/bitfield5.C b/gcc/testsuite/g++.dg/expr/bitfield5.C index 3d18e159cc0..0a37f9f166b 100644 --- a/gcc/testsuite/g++.dg/expr/bitfield5.C +++ b/gcc/testsuite/g++.dg/expr/bitfield5.C @@ -8,10 +8,10 @@ struct S { S s; int main() { - s.x++; + s.x++; // { dg-warning "deprecated" } if (s.x != 1) return 1; - ++s.x; + ++s.x; // { dg-warning "deprecated" } if (s.x != 1) return 2; } diff --git a/gcc/testsuite/g++.dg/expr/bitfield6.C b/gcc/testsuite/g++.dg/expr/bitfield6.C index 6f6d559a38e..8523866cd9d 100644 --- a/gcc/testsuite/g++.dg/expr/bitfield6.C +++ b/gcc/testsuite/g++.dg/expr/bitfield6.C @@ -7,5 +7,5 @@ struct S { S s; void f() { - ++s.x = false; + ++s.x = false; // { dg-warning "deprecated" } } diff --git a/gcc/testsuite/g++.dg/expr/bool1.C b/gcc/testsuite/g++.dg/expr/bool1.C index bfb40e33092..503e8b40c8c 100644 --- a/gcc/testsuite/g++.dg/expr/bool1.C +++ b/gcc/testsuite/g++.dg/expr/bool1.C @@ -10,8 +10,8 @@ int main() my_bool b = false; int i; - b++; - b++; + b++; // { dg-warning "deprecated" } + b++; // { dg-warning "deprecated" } i = b; if (i != 1) abort (); diff --git a/gcc/testsuite/g++.dg/expr/bool3.C b/gcc/testsuite/g++.dg/expr/bool3.C index 61669e27bef..1866ed47e9d 100644 --- a/gcc/testsuite/g++.dg/expr/bool3.C +++ b/gcc/testsuite/g++.dg/expr/bool3.C @@ -10,8 +10,8 @@ int main() my_bool b = false; int i; - b++; - b++; + b++; // { dg-warning "deprecated" } + b++; // { dg-warning "deprecated" } i = b; if (i != 1) abort (); diff --git a/gcc/testsuite/g++.dg/expr/lval3.C b/gcc/testsuite/g++.dg/expr/lval3.C index f106e69619d..8e0aeade4b9 100644 --- a/gcc/testsuite/g++.dg/expr/lval3.C +++ b/gcc/testsuite/g++.dg/expr/lval3.C @@ -4,6 +4,7 @@ f() { bool i = 0; i++ = 3; // { dg-error "" } + // { dg-warning "deprecated" "" { target *-*-* } 6 } } diff --git a/gcc/testsuite/g++.dg/expr/lval4.C b/gcc/testsuite/g++.dg/expr/lval4.C index c66e2f6af25..b903ec8c39e 100644 --- a/gcc/testsuite/g++.dg/expr/lval4.C +++ b/gcc/testsuite/g++.dg/expr/lval4.C @@ -4,6 +4,7 @@ f() { bool i = 0; ++i = 3; + // { dg-warning "deprecated" "" { target *-*-* } 6 } } diff --git a/gcc/testsuite/g++.dg/gomp/atomic-14.C b/gcc/testsuite/g++.dg/gomp/atomic-14.C index ae1eb50dcd6..982f44fae92 100644 --- a/gcc/testsuite/g++.dg/gomp/atomic-14.C +++ b/gcc/testsuite/g++.dg/gomp/atomic-14.C @@ -8,12 +8,12 @@ int foo (void) { #pragma omp atomic - (*baz ())--; // { dg-error "invalid use of Boolean" } + (*baz ())--; // { dg-error "use of an operand of type .bool." } #pragma omp atomic - --(*baz ()); // { dg-error "invalid use of Boolean" } + --(*baz ()); // { dg-error "use of an operand of type .bool." } #pragma omp atomic - atomicvar--; // { dg-error "invalid use of Boolean" } + atomicvar--; // { dg-error "use of an operand of type .bool." } #pragma omp atomic - --atomicvar; // { dg-error "invalid use of Boolean" } + --atomicvar; // { dg-error "use of an operand of type .bool." } return 0; } diff --git a/gcc/testsuite/g++.dg/other/error18.C b/gcc/testsuite/g++.dg/other/error18.C index 9e4d21cfde0..05ddf116675 100644 --- a/gcc/testsuite/g++.dg/other/error18.C +++ b/gcc/testsuite/g++.dg/other/error18.C @@ -7,5 +7,5 @@ struct A void f(A a) { - a.b--; // { dg-error "Boolean expression" } + a.b--; // { dg-error "use of an operand of type .bool." } } diff --git a/gcc/testsuite/g++.old-deja/g++.jason/bool5.C b/gcc/testsuite/g++.old-deja/g++.jason/bool5.C index 1d2f5b60b46..0a16ccb16ac 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/bool5.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/bool5.C @@ -2,10 +2,10 @@ int main () { bool b = false; - int i = b++; + int i = b++; // { dg-warning "deprecated" } if (i != false || b != true) return 1; - i = b++; + i = b++; // { dg-warning "deprecated" } if (i != true || b != true) return 1; } diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 32b11ec067f..e7749b2be4e 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,7 @@ +2016-09-14 Marek Polacek + + * testsuite/libgomp.c++/atomic-3.C: Use -Wno-deprecated. + 2016-08-19 Jakub Jelinek PR fortran/71014 diff --git a/libgomp/testsuite/libgomp.c++/atomic-3.C b/libgomp/testsuite/libgomp.c++/atomic-3.C index 660b260e19f..f957b2fece5 100644 --- a/libgomp/testsuite/libgomp.c++/atomic-3.C +++ b/libgomp/testsuite/libgomp.c++/atomic-3.C @@ -1,4 +1,5 @@ // { dg-do run } +// { dg-options "-Wno-deprecated" } extern "C" void abort (void); bool v, x1, x2, x3, x4, x5, x6; diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1ec0981a5e3..cb6e964f69a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2016-09-14 Marek Polacek + + * testsuite/23_containers/vector/debug/insert6_neg.cc: Use + -Wno-deprecated. + 2016-09-14 Christophe Lyon * testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/insert6_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/insert6_neg.cc index 9893293613f..c939c2203fc 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/debug/insert6_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/insert6_neg.cc @@ -16,6 +16,7 @@ // . // // { dg-do run { xfail *-*-* } } +// { dg-options "-Wno-deprecated" } #include #include -- 2.30.2