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
This commit is contained in:
parent
f335184d24
commit
20a1e5b8c8
24 changed files with 93 additions and 25 deletions
|
@ -1,3 +1,8 @@
|
|||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" } } */
|
||||
|
|
|
@ -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" } } */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* PR middle-end/45423 */
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-fopenmp" } */
|
||||
/* { dg-options "-fopenmp -Wno-deprecated" } */
|
||||
|
||||
#ifdef __cplusplus
|
||||
bool *baz ();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,5 +16,4 @@ int main(){
|
|||
foo(3.14f);
|
||||
foo(0);
|
||||
foo('a');
|
||||
foo(false);
|
||||
}
|
||||
|
|
14
gcc/testsuite/g++.dg/cpp1z/bool-increment1.C
Normal file
14
gcc/testsuite/g++.dg/cpp1z/bool-increment1.C
Normal file
|
@ -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;
|
||||
}
|
|
@ -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." }
|
||||
}
|
||||
|
|
|
@ -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" }
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@ struct S {
|
|||
S s;
|
||||
|
||||
void f() {
|
||||
++s.x = false;
|
||||
++s.x = false; // { dg-warning "deprecated" }
|
||||
}
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -4,6 +4,7 @@ f()
|
|||
{
|
||||
bool i = 0;
|
||||
i++ = 3; // { dg-error "" }
|
||||
// { dg-warning "deprecated" "" { target *-*-* } 6 }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ f()
|
|||
{
|
||||
bool i = 0;
|
||||
++i = 3;
|
||||
// { dg-warning "deprecated" "" { target *-*-* } 6 }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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." }
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// { dg-do run }
|
||||
// { dg-options "-Wno-deprecated" }
|
||||
|
||||
extern "C" void abort (void);
|
||||
bool v, x1, x2, x3, x4, x5, x6;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// { dg-do run { xfail *-*-* } }
|
||||
// { dg-options "-Wno-deprecated" }
|
||||
|
||||
#include <vector>
|
||||
#include <debug/vector>
|
||||
|
|
Loading…
Add table
Reference in a new issue