diff options
author | Jason Merrill <jason@redhat.com> | 2012-09-17 12:06:03 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2012-09-17 12:06:03 -0400 |
commit | 5e23183b939c78a747502e45c63b2271ace49eb0 (patch) | |
tree | a8916e748bdf9ead6ef56f79d4e070c22ce1ac47 | |
parent | f57f20bb753e877d9285fd75dd6b46fa244bb27f (diff) | |
download | gcc-5e23183b939c78a747502e45c63b2271ace49eb0.zip gcc-5e23183b939c78a747502e45c63b2271ace49eb0.tar.gz gcc-5e23183b939c78a747502e45c63b2271ace49eb0.tar.bz2 |
re PR c++/53661 (Wrong narrowing conversion warning with -std=c++11)
PR c++/53661
* typeck2.c (check_narrowing): Avoid false positives on conversion
from enumeral type.
From-SVN: r191395
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck2.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/aggr9.C | 9 |
4 files changed, 23 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f70b466..c11a8c2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-09-14 Jason Merrill <jason@redhat.com> + + PR c++/53661 + * typeck2.c (check_narrowing): Avoid false positives on conversion + from enumeral type. + 2012-09-14 Marc Glisse <marc.glisse@inria.fr> PR c++/54427 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 6faebb5..58b2db6 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -787,6 +787,9 @@ check_narrowing (tree type, tree init) else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype) && CP_INTEGRAL_TYPE_P (type)) { + if (TREE_CODE (ftype) == ENUMERAL_TYPE) + /* Check for narrowing based on the values of the enumeration. */ + ftype = ENUM_UNDERLYING_TYPE (ftype); if ((tree_int_cst_lt (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (ftype)) || tree_int_cst_lt (TYPE_MIN_VALUE (ftype), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7581988..f978693 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-09-14 Jason Merrill <jason@redhat.com> + + PR c++/53661 + * g++.dg/init/aggr9.C: New. + 2012-09-17 Eric Botcazou <ebotcazou@adacore.com> * gnat.dg/loop_optimization12.ad[sb]: New test. diff --git a/gcc/testsuite/g++.dg/init/aggr9.C b/gcc/testsuite/g++.dg/init/aggr9.C new file mode 100644 index 0000000..67d8299 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/aggr9.C @@ -0,0 +1,9 @@ +// PR c++/53661 + +enum Code { + SUCCESS = 0 +}; + +Code a; + +int r[] = {a}; |