diff options
24 files changed, 93 insertions, 25 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index df4655e..001479c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2016-09-14 Marek Polacek <polacek@redhat.com> + * typeck.c (cp_build_unary_op): Diagnose incrementing boolean + expressions. Tweak an error message. + +2016-09-14 Marek Polacek <polacek@redhat.com> + * cp-tree.h (cp_build_unary_op): Change nonconvert parameter type to bool. * decl2.c (one_static_initialization_or_destruction): Use true instead diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c51d6d0..c53a85a 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 %<operator--%>"); + error ("use of an operand of type %qT in %<operator--%> " + "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 " + "%<operator++%> 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 %<operator++%> 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 e394dcd..dc55a3d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,23 @@ +2016-09-14 Marek Polacek <polacek@redhat.com> + + * 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 <nathan@acm.org> 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 145e420..e9ca650 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 2452035..7f4afcf 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 f8fc9d8..7e23453 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 68bd33c..71b397a 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 f7525d8..4d434cd 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 0000000..ae2dcf9 --- /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 3221263..3f30337 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 d824964..7fae086 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 3d18e15..0a37f9f 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 6f6d559..8523866 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 bfb40e3..503e8b4 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 61669e2..1866ed4 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 f106e69..8e0aead 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 c66e2f6a..b903ec8 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 ae1eb50d..982f44f 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 9e4d21c..05ddf11 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 1d2f5b6..0a16ccb 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 32b11ec..e7749b2 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,7 @@ +2016-09-14 Marek Polacek <polacek@redhat.com> + + * testsuite/libgomp.c++/atomic-3.C: Use -Wno-deprecated. + 2016-08-19 Jakub Jelinek <jakub@redhat.com> PR fortran/71014 diff --git a/libgomp/testsuite/libgomp.c++/atomic-3.C b/libgomp/testsuite/libgomp.c++/atomic-3.C index 660b260..f957b2f 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 1ec0981..cb6e964 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2016-09-14 Marek Polacek <polacek@redhat.com> + + * testsuite/23_containers/vector/debug/insert6_neg.cc: Use + -Wno-deprecated. + 2016-09-14 Christophe Lyon <christophe.lyon@linaro.org> * 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 9893293..c939c22 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 @@ // <http://www.gnu.org/licenses/>. // // { dg-do run { xfail *-*-* } } +// { dg-options "-Wno-deprecated" } #include <vector> #include <debug/vector> |