aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2005-10-14 19:50:08 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2005-10-14 19:50:08 +0000
commit3c955a0481f042373c9390273a4560d08455d51f (patch)
treea92acb52906f3524fb18cda3d190a9e9183cb38e /gcc
parent21dac32c3c6e6a26fef2639662a1bff50166e58d (diff)
downloadgcc-3c955a0481f042373c9390273a4560d08455d51f.zip
gcc-3c955a0481f042373c9390273a4560d08455d51f.tar.gz
gcc-3c955a0481f042373c9390273a4560d08455d51f.tar.bz2
re PR c++/19565 (g++ does not warn about overflow in conversion but gcc does)
PR c++/19565 * g++.dg/warn/Wconversion1.C: New test. * g++.dg/ext/packed4.C: Compile with -w. * g++.dg/opt/20050511-1.C: Likewise. * g++.old-deja/g++.other/warn4.C: Compiler with -Wconversion. From-SVN: r105421
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/call.c24
-rw-r--r--gcc/cp/decl.c12
-rw-r--r--gcc/cp/typeck2.c6
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/ext/packed4.C1
-rw-r--r--gcc/testsuite/g++.dg/opt/20050511-1.C3
-rw-r--r--gcc/testsuite/g++.dg/warn/Wconversion1.C12
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/warn4.C1
9 files changed, 56 insertions, 23 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 00e0af2..7b2ff85 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2005-10-14 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/19565
+ * call.c (convert_like_real): Rely on convert_and_check to issue
+ warnings about overflow and conversion to unsigned.
+ * decl.c (finish_enum): Use the location of the enumerators, not
+ the closing brace of the enumeration, when reporting warnings
+ about conversions.
+ (build_enumerator): Use error_mark_node for erroneous values.
+ * typeck2.c (digest_init): Remove reference to "signature pointer"
+ from comment.
+
2005-10-14 Nathan Sidwell <nathan@codesourcery.com>
PR c++/17796
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 9247605..fe8d62e 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4216,21 +4216,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
else
warning (0, "converting to %qT from %qT", t, TREE_TYPE (expr));
}
- /* And warn about assigning a negative value to an unsigned
- variable. */
- else if (TYPE_UNSIGNED (t) && TREE_CODE (t) != BOOLEAN_TYPE)
- {
- if (TREE_CODE (expr) == INTEGER_CST && TREE_NEGATED_INT (expr))
- {
- if (fn)
- warning (0, "passing negative value %qE for argument %P to %qD",
- expr, argnum, fn);
- else
- warning (0, "converting negative value %qE to %qT", expr, t);
- }
-
- overflow_warning (expr);
- }
}
switch (convs->kind)
@@ -4430,8 +4415,13 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
default:
break;
}
- return ocp_convert (totype, expr, CONV_IMPLICIT,
- LOOKUP_NORMAL|LOOKUP_NO_CONVERSION);
+
+ if (issue_conversion_warnings)
+ expr = convert_and_check (totype, expr);
+ else
+ expr = convert (totype, expr);
+
+ return expr;
}
/* Build a call to __builtin_trap. */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7cc2fde..56c2d4d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9750,6 +9750,8 @@ finish_enum (tree enumtype)
/* Update the minimum and maximum values, if appropriate. */
value = DECL_INITIAL (decl);
+ if (value == error_mark_node)
+ value = integer_zero_node;
/* Figure out what the minimum and maximum values of the
enumerators are. */
if (!minnode)
@@ -9852,9 +9854,14 @@ finish_enum (tree enumtype)
type of the enumeration. */
for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
{
+ location_t saved_location;
+
decl = TREE_VALUE (values);
+ saved_location = input_location;
+ input_location = DECL_SOURCE_LOCATION (decl);
value = perform_implicit_conversion (underlying_type,
DECL_INITIAL (decl));
+ input_location = saved_location;
/* Do not clobber shared ints. */
value = copy_node (value);
@@ -9944,7 +9951,10 @@ build_enumerator (tree name, tree value, tree enumtype)
overflowed |= !int_fits_type_p (value, TREE_TYPE (prev_value));
if (overflowed)
- error ("overflow in enumeration values at %qD", name);
+ {
+ error ("overflow in enumeration values at %qD", name);
+ value = error_mark_node;
+ }
}
else
value = integer_zero_node;
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index e9a6161..42520e2 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -695,10 +695,8 @@ digest_init (tree type, tree init)
}
}
- /* Handle scalar types, including conversions,
- and signature pointers and references. */
- if (SCALAR_TYPE_P (type)
- || code == REFERENCE_TYPE)
+ /* Handle scalar types (including conversions) and references. */
+ if (SCALAR_TYPE_P (type) || code == REFERENCE_TYPE)
return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
"initialization", NULL_TREE, 0);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fcb7bec..877bca8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2005-10-14 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/19565
+ * g++.dg/warn/Wconversion1.C: New test.
+ * g++.dg/ext/packed4.C: Compile with -w.
+ * g++.dg/opt/20050511-1.C: Likewise.
+ * g++.old-deja/g++.other/warn4.C: Compiler with -Wconversion.
+
2005-10-14 Jakub Jelinek <jakub@redhat.com>
* gfortran.dg/boz_5.f90: New test.
diff --git a/gcc/testsuite/g++.dg/ext/packed4.C b/gcc/testsuite/g++.dg/ext/packed4.C
index 1ac9048..db1f5c9 100644
--- a/gcc/testsuite/g++.dg/ext/packed4.C
+++ b/gcc/testsuite/g++.dg/ext/packed4.C
@@ -1,4 +1,5 @@
// { dg-do run }
+// { dg-options "-w" }
// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Jul 2003 <nathan@codesourcery.com>
diff --git a/gcc/testsuite/g++.dg/opt/20050511-1.C b/gcc/testsuite/g++.dg/opt/20050511-1.C
index e04b2b8..2fbd3e1 100644
--- a/gcc/testsuite/g++.dg/opt/20050511-1.C
+++ b/gcc/testsuite/g++.dg/opt/20050511-1.C
@@ -1,5 +1,6 @@
/* { dg-do run } */
-/* { dg-options "-O3" { target powerpc*-*-* } } */
+/* { dg-options "-w" } */
+/* { dg-options "-O3 -w" { target powerpc*-*-* } } */
#include <stdio.h>
#include <stdlib.h>
diff --git a/gcc/testsuite/g++.dg/warn/Wconversion1.C b/gcc/testsuite/g++.dg/warn/Wconversion1.C
new file mode 100644
index 0000000..b3fbc30
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wconversion1.C
@@ -0,0 +1,12 @@
+// { dg-options "-Wconversion" }
+
+char c1 = 1024; // { dg-warning "overflow" }
+char c2 = char(1024);
+char c3 = (char) 1024;
+char c4 = static_cast<char>(1024);
+
+unsigned char uc1 = -129; // { dg-warning "unsigned" }
+
+bool b1 = -3;
+
+int i1 = 0x80000000;
diff --git a/gcc/testsuite/g++.old-deja/g++.other/warn4.C b/gcc/testsuite/g++.old-deja/g++.other/warn4.C
index dca3ed4..6cb4785 100644
--- a/gcc/testsuite/g++.old-deja/g++.other/warn4.C
+++ b/gcc/testsuite/g++.old-deja/g++.other/warn4.C
@@ -1,4 +1,5 @@
// { dg-do assemble }
+// { dg-options "-Wconversion" }
// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 21 Nov 1999 <nathan@acm.org>