diff options
| author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-08-04 19:53:57 +0000 |
|---|---|---|
| committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-08-04 19:53:57 +0000 |
| commit | 35db9bbc378e9608de892f5f3e17670e99ce701d (patch) | |
| tree | 02c27d8f0f6946c6d8018b380fa69f12c3010c78 | |
| parent | d17e11be473e2e98a6f29b68b5ca4309aa8aeea1 (diff) | |
| download | ppe42-gcc-35db9bbc378e9608de892f5f3e17670e99ce701d.tar.gz ppe42-gcc-35db9bbc378e9608de892f5f3e17670e99ce701d.zip | |
PR c++/36963
* typeck2.c (check_narrowing): Allow narrowing conversion
from an explicit floating-point constant.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138652 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
| -rw-r--r-- | gcc/cp/typeck2.c | 13 | ||||
| -rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/initlist5.C | 4 |
3 files changed, 19 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1918189a11b..8ff23cdb5dd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2008-08-04 Jason Merrill <jason@redhat.com> + PR c++/36963 + * typeck2.c (check_narrowing): Allow narrowing conversion + from an explicit floating-point constant. + PR c++/37006 * pt.c (tsubst_decl): Leave DECL_INITIAL set on deleted instantiations. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index ee686fecf33..787f43963d6 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -640,9 +640,13 @@ check_narrowing (tree type, tree init) tree ftype = TREE_TYPE (init); bool ok = true; REAL_VALUE_TYPE d; + bool was_decl = false; if (DECL_P (init)) - init = decl_constant_value (init); + { + was_decl = true; + init = decl_constant_value (init); + } if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (ftype) == REAL_TYPE) @@ -664,7 +668,12 @@ check_narrowing (tree type, tree init) if (TREE_CODE (init) == REAL_CST) { d = TREE_REAL_CST (init); - if (exact_real_truncate (TYPE_MODE (type), &d)) + if (exact_real_truncate (TYPE_MODE (type), &d) + /* FIXME: As a temporary workaround for PR 36963, don't + complain about narrowing from a floating + literal. Hopefully this will be resolved at the + September 2008 C++ meeting. */ + || !was_decl) ok = true; } } diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist5.C b/gcc/testsuite/g++.dg/cpp0x/initlist5.C index 0d02fd42d7f..fbdc673948f 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist5.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist5.C @@ -19,3 +19,7 @@ C c2 = { 1.1, 2 }; // { dg-error "narrowing" } int j { 1 }; // initialize to 1 int k {}; // initialize to 0 + +// PR c++/39693 +double d = 1.1; +float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" } |

