aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-11-08 15:17:42 -0500
committerJason Merrill <jason@gcc.gnu.org>2010-11-08 15:17:42 -0500
commit9e115cec97350099177071bb16b3efcbbacc9445 (patch)
tree29e021e2fec06d40962f55e47d182c721d950eae /gcc/testsuite
parent1b2c3293fbe12f7fa3254af12e9d0ca98d89c5aa (diff)
downloadgcc-9e115cec97350099177071bb16b3efcbbacc9445.zip
gcc-9e115cec97350099177071bb16b3efcbbacc9445.tar.gz
gcc-9e115cec97350099177071bb16b3efcbbacc9445.tar.bz2
Correct conversion/overflow behavior.
* cvt.c (ignore_overflows): Move here from typeck.c. (ocp_convert): Use it. (cp_fold_convert): Use it. Don't call rvalue. * typeck.c (build_static_cast_1): Don't use it. Do call rvalue. * error.c (location_of): Handle expressions, too. * class.c (check_bitfield_decl): Set input_location around call to cxx_constant_value. * semantics.c (cxx_eval_outermost_constant_expr): Don't print the expression if it already had TREE_OVERFLOW set. (reduced_constant_expression_p): Check TREE_OVERFLOW_P for C++98, too. (verify_constant): Allow overflow with a permerror if we're enforcing. (cxx_eval_outermost_constant_expr): Use verify_constant. (adjust_temp_type): Use cp_fold_convert. * decl.c (build_enumerator): Don't call constant_expression_warning. * decl2.c (grokbitfield): Likewise. From-SVN: r166453
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/expr/overflow1.C8
-rw-r--r--gcc/testsuite/g++.dg/warn/overflow-warn-1.C12
-rw-r--r--gcc/testsuite/g++.dg/warn/overflow-warn-3.C2
-rw-r--r--gcc/testsuite/g++.dg/warn/overflow-warn-4.C17
-rw-r--r--gcc/testsuite/g++.dg/warn/overflow-warn-5.C8
6 files changed, 41 insertions, 14 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 74d974b..7d2688e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2010-11-08 Jason Merrill <jason@redhat.com>
+
+ * g++.dg/expr/overflow1.C: New.
+ * g++.dg/warn/overflow-warn-1.C: Add expected diagnostics.
+ * g++.dg/warn/overflow-warn-3.C: Remove unnecessary line number.
+ * g++.dg/warn/overflow-warn-4.C: Add expected diagnostics.
+ * g++.dg/warn/overflow-warn-5.C: Don't expect wrong warning.
+
2010-11-08 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* gcc.dg/pr35442.c: Adapt warning.
diff --git a/gcc/testsuite/g++.dg/expr/overflow1.C b/gcc/testsuite/g++.dg/expr/overflow1.C
new file mode 100644
index 0000000..b67b4e42
--- /dev/null
+++ b/gcc/testsuite/g++.dg/expr/overflow1.C
@@ -0,0 +1,8 @@
+#include <limits.h>
+
+enum E {
+ A = (unsigned char)-1, /* OK */
+ B = (signed char)UCHAR_MAX, /* implementation-defined */
+ C = INT_MAX+1, /* undefined (C)/ill-formed (C++) { dg-message "" } */
+ D = UINT_MAX+1 /* OK */
+};
diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-1.C b/gcc/testsuite/g++.dg/warn/overflow-warn-1.C
index 17bd067..22c512a 100644
--- a/gcc/testsuite/g++.dg/warn/overflow-warn-1.C
+++ b/gcc/testsuite/g++.dg/warn/overflow-warn-1.C
@@ -1,7 +1,7 @@
/* Test for diagnostics for constant overflow. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-fpermissive" } */
#include <limits.h>
@@ -19,8 +19,10 @@ enum e {
E4 = 0 * (1 / 0), /* { dg-warning "division by zero" } */
/* { dg-error "enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */
E5 = INT_MAX + 1, /* { dg-warning "integer overflow in expression" } */
+ /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 21 } */
/* Again, overflow in evaluated subexpression. */
E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */
+ /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 24 } */
/* A cast does not constitute overflow in conversion. */
E7 = (char) INT_MAX
};
@@ -29,6 +31,7 @@ struct s {
int a;
int : 0 * (1 / 0); /* { dg-warning "division by zero" } */
int : 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
+ /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 33 } */
};
void
@@ -49,10 +52,10 @@ void *n = 0;
constants. The third has the overflow in an unevaluated
subexpression, so is a null pointer constant. */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
-/* { dg-error "invalid conversion from 'int' to 'void" "null" { target *-*-* } 51 } */
+/* { dg-warning "invalid conversion from 'int' to 'void" "null" { target *-*-* } 54 } */
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
-/* { dg-error "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 53 } */
-void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } 55 } */
+/* { dg-error "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 56 } */
+void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } } */
void
g (int i)
@@ -62,6 +65,7 @@ g (int i)
case 0 * (1/0): /* { dg-warning "division by zero" } */
;
case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */
+ /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 67 } */
;
}
}
diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-3.C b/gcc/testsuite/g++.dg/warn/overflow-warn-3.C
index ce03a97..d88c87a 100644
--- a/gcc/testsuite/g++.dg/warn/overflow-warn-3.C
+++ b/gcc/testsuite/g++.dg/warn/overflow-warn-3.C
@@ -57,7 +57,7 @@ void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" }
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
/* { dg-warning "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 58 } */
-void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } 60 } */
+void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } } */
void
g (int i)
diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-4.C b/gcc/testsuite/g++.dg/warn/overflow-warn-4.C
index 0c916d0..374d2942 100644
--- a/gcc/testsuite/g++.dg/warn/overflow-warn-4.C
+++ b/gcc/testsuite/g++.dg/warn/overflow-warn-4.C
@@ -11,7 +11,7 @@ enum e {
E1 = UINT_MAX + 1,
/* Overflow in an unevaluated part of an expression is OK (example
in the standard). */
- E2 = 2 || 1 / 0, /* { dg-bogus "warning: division by zero" "" { xfail *-*-* } 14 } */
+ E2 = 2 || 1 / 0, /* { dg-bogus "warning: division by zero" "" { xfail *-*-* } } */
E3 = 1 / 0, /* { dg-warning "division by zero" } */
/* { dg-error "enumerator value for 'E3' is not an integer constant|not a constant expression" "enum error" { target *-*-* } 15 } */
/* But as in DR#031, the 1/0 in an evaluated subexpression means the
@@ -20,9 +20,11 @@ enum e {
/* { dg-error "enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */
E5 = INT_MAX + 1, /* { dg-warning "integer overflow in expression" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } 21 } */
+ /* { dg-error "enumerator value for 'E5' is not an integer constant" "enum error" { target *-*-* } 21 } */
/* Again, overflow in evaluated subexpression. */
E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */
- /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 24 } */
+ /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 25 } */
+ /* { dg-error "enumerator value for 'E6' is not an integer constant" "enum error" { target *-*-* } 25 } */
/* A cast does not constitute overflow in conversion. */
E7 = (char) INT_MAX
};
@@ -31,7 +33,8 @@ struct s {
int a;
int : 0 * (1 / 0); /* { dg-warning "division by zero" } */
int : 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
- /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 33 } */
+ /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 35 } */
+ /* { dg-error "bit-field .* width not an integer constant" "" { target *-*-* } 35 } */
};
void
@@ -53,11 +56,11 @@ void *n = 0;
constants. The third has the overflow in an unevaluated
subexpression, so is a null pointer constant. */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
-/* { dg-error "invalid conversion from 'int' to 'void" "null" { target *-*-* } 55 } */
+/* { dg-error "invalid conversion from 'int' to 'void" "null" { target *-*-* } 58 } */
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
-/* { dg-error "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 58 } */
-void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } 60 } */
+/* { dg-error "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 61 } */
+void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } } */
void
g (int i)
@@ -67,7 +70,7 @@ g (int i)
case 0 * (1/0): /* { dg-warning "division by zero" } */
;
case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */
- /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 69 } */
+ /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 72 } */
;
}
}
diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-5.C b/gcc/testsuite/g++.dg/warn/overflow-warn-5.C
index 472d4a7..bdfec4a 100644
--- a/gcc/testsuite/g++.dg/warn/overflow-warn-5.C
+++ b/gcc/testsuite/g++.dg/warn/overflow-warn-5.C
@@ -1,7 +1,11 @@
/* PR c/27273 */
/* { dg-do compile } */
-/* { dg-options "-Woverflow" } */
+
+// This used to warn about "overflow in implicit constant conversion",
+// which was wrong; 512 is never converted to unsigned char. Rather, an
+// appropriate warning would be that the & expression always evaluates to 0
+// because of the limited range of unsigned char.
unsigned char rx_async(unsigned char p) {
- return p & 512; /* { dg-warning "overflow in implicit constant conversion" } */
+ return p & 512; /* { dg-warning "" "" { xfail *-*-* } } */
}