This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++] Explicitly test for TREE_CONSTANT_OVERFLOW in null_ptr_cst_p
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Mon, 3 Apr 2006 10:26:42 -0600 (MDT)
- Subject: [C++] Explicitly test for TREE_CONSTANT_OVERFLOW in null_ptr_cst_p
Many thanks to Joseph for pointing out that the g++ front-end's code
probably isn't yet checking for overflow of null pointers constants
explicitly. Indeed, it's not and there's no test case for this in the
g++ testsuite. The patch below adds an explicit TREE_CONSTANT_OVERFLOW
check to null_ptr_cst_p and adds a new g++.dg/conversion test case to
ensure this doesn't break in future. Whilst I was at it, I decided to
also add another nullptr?.C test case to test the resolution of
PR c++/14644.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", including c++, and regression tested with a top-level
"make -k check" with no new failures.
Ok for mainline?
2006-04-03 Roger Sayle <roger@eyesopen.com>
* call.c (null_ptr_cst_p): Add explicit TREE_CONSTANT_OVERFLOW check.
* g++.dg/conversion/nullptr1.C: New test case.
* g++.dg/conversion/nullptr2.C: Likewise.
Index: call.c
===================================================================
*** call.c (revision 112522)
--- call.c (working copy)
*************** null_ptr_cst_p (tree t)
*** 427,433 ****
(_expr.const_) rvalue of integer type that evaluates to zero. */
t = integral_constant_value (t);
if (t == null_node
! || (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)) && integer_zerop (t)))
return true;
return false;
}
--- 427,435 ----
(_expr.const_) rvalue of integer type that evaluates to zero. */
t = integral_constant_value (t);
if (t == null_node
! || (CP_INTEGRAL_TYPE_P (TREE_TYPE (t))
! && integer_zerop (t)
! && !TREE_CONSTANT_OVERFLOW (t)))
return true;
return false;
}
/* Test for overflow in NULL pointer constant. */
/* { dg-do compile } */
#include <limits.h>
void *p = 0;
void *q = 0 * (INT_MAX + 1); // { dg-error "invalid conversion" }
/* Test for enumeration as NULL pointer constant. */
/* PR c++/14644 */
/* { dg-do compile } */
enum { NULL = 0 };
void *p = 0;
void *q = NULL; // { dg-error "cannot convert" }
Roger
--