From: Andrew Pinski Date: Thu, 17 Sep 2009 23:03:55 +0000 (-0700) Subject: re PR c++/39365 (++ operator with volatile bool increments) X-Git-Tag: releases/gcc-4.5.0~3449 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66be89f022efde50e624af8f67c67b3e4875df5c;p=thirdparty%2Fgcc.git re PR c++/39365 (++ operator with volatile bool increments) 2009-09-17 Andrew Pinski PR c++/39365 * typeck.c (cp_build_unary_op): Check TREE_CODE for bools instead of using same_type_p. (convert_for_assignment): Likewise. * cvt.c (type_promotes_to): Likewise. 2009-09-17 Andrew Pinski PR c++/39365 * g++.dg/expr/bool3.C: New test. * g++.dg/expr/bool4.C: New test. From-SVN: r151823 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 93b90b5c0ee5..8bf0dde42265 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-09-17 Andrew Pinski + + PR c++/39365 + * g++.dg/expr/bool3.C: New test. + * g++.dg/expr/bool4.C: New test. + 2009-09-14 Richard Henderson Jakub Jelinek diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index cdc6a10a825e..aff002dc6666 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1287,7 +1287,7 @@ type_promotes_to (tree type) /* bool always promotes to int (not unsigned), even if it's the same size. */ - if (type == boolean_type_node) + if (TREE_CODE (type) == BOOLEAN_TYPE) type = integer_type_node; /* Normally convert enums to int, but convert wide enums to something diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 53165b38dc30..059511396c5f 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4556,7 +4556,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, return error_mark_node; /* Forbid using -- on `bool'. */ - if (same_type_p (declared_type, boolean_type_node)) + if (TREE_CODE (declared_type) == BOOLEAN_TYPE) { if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR) { @@ -6787,7 +6787,7 @@ convert_for_assignment (tree type, tree rhs, /* If -Wparentheses, warn about a = b = c when a has type bool and b does not. */ if (warn_parentheses - && type == boolean_type_node + && TREE_CODE (type) == BOOLEAN_TYPE && TREE_CODE (rhs) == MODIFY_EXPR && !TREE_NO_WARNING (rhs) && TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 67cf3a969d8a..c53270b79ce5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2009-09-17 Andrew Pinski + + PR c++/39365 + * typeck.c (cp_build_unary_op): Check TREE_CODE for bools instead of + using same_type_p. + (convert_for_assignment): Likewise. + * cvt.c (type_promotes_to): Likewise. + 2009-09-17 Janis Johnson * gcc/testsuite/gcc.dg/dfp/dfp-dbg.h: Define EXTERN. diff --git a/gcc/testsuite/g++.dg/expr/bool3.C b/gcc/testsuite/g++.dg/expr/bool3.C new file mode 100644 index 000000000000..61669e27befd --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/bool3.C @@ -0,0 +1,21 @@ +// { dg-do run } +// PR C++/29295 +// make sure that a typedef for a bool will have the +// the same results as a bool itself. + +extern "C" void abort(); +typedef volatile bool my_bool; +int main() +{ + my_bool b = false; + int i; + + b++; + b++; + i = b; + if (i != 1) + abort (); + return 0; +} + + diff --git a/gcc/testsuite/g++.dg/expr/bool4.C b/gcc/testsuite/g++.dg/expr/bool4.C new file mode 100644 index 000000000000..dce51ec332e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/bool4.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// make sure that a typedef for a bool will have the +// the same results as a bool itself. + + +typedef volatile bool my_bool; +int main() +{ + my_bool b = false; + b--; // { dg-error "" } + return 0; +} +