aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck2.c16
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist5.C4
4 files changed, 21 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f533944..a4eb86a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-20 Jason Merrill <jason@redhat.com>
+
+ C++ core issue 703
+ * typeck2.c (check_narrowing): Don't complain about loss of
+ precision when converting a floating-point constant.
+
2009-03-19 Jakub Jelinek <jakub@redhat.com>
PR c/39495
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 6370765..747c964 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -677,18 +677,18 @@ check_narrowing (tree type, tree init)
{
if (TYPE_PRECISION (type) < TYPE_PRECISION (ftype))
{
- ok = false;
if (TREE_CODE (init) == REAL_CST)
{
+ /* Issue 703: Loss of precision is OK as long as the value is
+ within the representable range of the new type. */
+ REAL_VALUE_TYPE r;
d = TREE_REAL_CST (init);
- 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;
+ real_convert (&r, TYPE_MODE (type), &d);
+ if (real_isinf (&r))
+ ok = false;
}
+ else
+ ok = false;
}
}
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c7c1e58..16d50f4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2009-03-20 Jason Merrill <jason@redhat.com>
+
+ * g++.dg/cpp0x/initlist5.C: Add additional test.
+
2009-03-19 Jakub Jelinek <jakub@redhat.com>
Janis Johnson <janis187@us.ibm.com>
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist5.C b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
index fbdc673..958007c 100644
--- a/gcc/testsuite/g++.dg/cpp0x/initlist5.C
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist5.C
@@ -20,6 +20,8 @@ C c2 = { 1.1, 2 }; // { dg-error "narrowing" }
int j { 1 }; // initialize to 1
int k {}; // initialize to 0
-// PR c++/39693
+// PR c++/36963
double d = 1.1;
float fa[] = { d, 1.1 }; // { dg-error "narrowing conversion of 'd'" }
+const double d2 = 1.1;
+float fa2[] = { d2, 1.1 };