re PR c++/19457 (Warning depends on cached constant)
PR c++/19457 * call.c (convert_like_real): Inline call to dubious_conversion_warnings here. * cp-tree.h (dubious_conversion_warnings): Remove. * semantics.c (finish_unary_op_expr): Copy INTEGER_CSTs before setting TREE_NEGATED_INT. * typeck.c (dubious_conversion_warnings): Remove. PR c++/19349 * name-lookup.c (pushdecl_namespace_level): Avoid accessing free'd memory. PR c++/19457 * g++.dg/warn/conv3.C: New test. From-SVN: r94463
This commit is contained in:
parent
ef3f522837
commit
6fc98adf76
|
@ -1,3 +1,17 @@
|
|||
2005-01-30 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
PR c++/19457
|
||||
* call.c (convert_like_real): Inline call to
|
||||
dubious_conversion_warnings here.
|
||||
* cp-tree.h (dubious_conversion_warnings): Remove.
|
||||
* semantics.c (finish_unary_op_expr): Copy INTEGER_CSTs before
|
||||
setting TREE_NEGATED_INT.
|
||||
* typeck.c (dubious_conversion_warnings): Remove.
|
||||
|
||||
PR c++/19349
|
||||
* name-lookup.c (pushdecl_namespace_level): Avoid accessing free'd
|
||||
memory.
|
||||
|
||||
2005-01-28 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
PR c++/19253
|
||||
|
|
|
@ -4166,8 +4166,46 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
|
|||
}
|
||||
|
||||
if (issue_conversion_warnings)
|
||||
expr = dubious_conversion_warnings
|
||||
(totype, expr, "converting", fn, argnum);
|
||||
{
|
||||
tree t = non_reference (totype);
|
||||
|
||||
/* Issue warnings about peculiar, but valid, uses of NULL. */
|
||||
if (ARITHMETIC_TYPE_P (t) && expr == null_node)
|
||||
{
|
||||
if (fn)
|
||||
warning ("passing NULL to non-pointer argument %P of %qD",
|
||||
argnum, fn);
|
||||
else
|
||||
warning ("converting to non-pointer type %qT from NULL", t);
|
||||
}
|
||||
|
||||
/* Warn about assigning a floating-point type to an integer type. */
|
||||
if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
|
||||
&& TREE_CODE (t) == INTEGER_TYPE)
|
||||
{
|
||||
if (fn)
|
||||
warning ("passing %qT for argument %P to %qD",
|
||||
TREE_TYPE (expr), argnum, fn);
|
||||
else
|
||||
warning ("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 ("passing negative value %qE for argument %P to %qD",
|
||||
expr, argnum, fn);
|
||||
else
|
||||
warning ("converting negative value %qE to %qT", expr, t);
|
||||
}
|
||||
|
||||
overflow_warning (expr);
|
||||
}
|
||||
}
|
||||
|
||||
switch (convs->kind)
|
||||
{
|
||||
case ck_user:
|
||||
|
|
|
@ -4298,7 +4298,6 @@ extern tree build_const_cast (tree, tree);
|
|||
extern tree build_c_cast (tree, tree);
|
||||
extern tree build_x_modify_expr (tree, enum tree_code, tree);
|
||||
extern tree build_modify_expr (tree, enum tree_code, tree);
|
||||
extern tree dubious_conversion_warnings (tree, tree, const char *, tree, int);
|
||||
extern tree convert_for_initialization (tree, tree, tree, int, const char *, tree, int);
|
||||
extern int comp_ptr_ttypes (tree, tree);
|
||||
extern int ptr_reasonably_similar (tree, tree);
|
||||
|
|
|
@ -3024,9 +3024,9 @@ pushdecl_namespace_level (tree x)
|
|||
|
||||
/* Now, the type_shadowed stack may screw us. Munge it so it does
|
||||
what we want. */
|
||||
if (TREE_CODE (x) == TYPE_DECL)
|
||||
if (TREE_CODE (t) == TYPE_DECL)
|
||||
{
|
||||
tree name = DECL_NAME (x);
|
||||
tree name = DECL_NAME (t);
|
||||
tree newval;
|
||||
tree *ptr = (tree *)0;
|
||||
for (; !global_scope_p (b); b = b->level_chain)
|
||||
|
@ -3041,12 +3041,12 @@ pushdecl_namespace_level (tree x)
|
|||
PT names. It's gross, but I haven't time to fix it. */
|
||||
}
|
||||
}
|
||||
newval = TREE_TYPE (x);
|
||||
newval = TREE_TYPE (t);
|
||||
if (ptr == (tree *)0)
|
||||
{
|
||||
/* @@ This shouldn't be needed. My test case "zstring.cc" trips
|
||||
up here if this is changed to an assertion. --KR */
|
||||
SET_IDENTIFIER_TYPE_VALUE (name, x);
|
||||
SET_IDENTIFIER_TYPE_VALUE (name, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1959,7 +1959,12 @@ finish_unary_op_expr (enum tree_code code, tree expr)
|
|||
&& TREE_CODE (result) == INTEGER_CST
|
||||
&& !TYPE_UNSIGNED (TREE_TYPE (result))
|
||||
&& INT_CST_LT (result, integer_zero_node))
|
||||
TREE_NEGATED_INT (result) = 1;
|
||||
{
|
||||
/* RESULT may be a cached INTEGER_CST, so we must copy it before
|
||||
setting TREE_NEGATED_INT. */
|
||||
result = copy_node (result);
|
||||
TREE_NEGATED_INT (result) = 1;
|
||||
}
|
||||
overflow_warning (result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -5813,57 +5813,6 @@ pfn_from_ptrmemfunc (tree t)
|
|||
return build_ptrmemfunc_access_expr (t, pfn_identifier);
|
||||
}
|
||||
|
||||
/* Expression EXPR is about to be implicitly converted to TYPE. Warn
|
||||
if this is a potentially dangerous thing to do. Returns a possibly
|
||||
marked EXPR. */
|
||||
|
||||
tree
|
||||
dubious_conversion_warnings (tree type, tree expr,
|
||||
const char *errtype, tree fndecl, int parmnum)
|
||||
{
|
||||
type = non_reference (type);
|
||||
|
||||
/* Issue warnings about peculiar, but valid, uses of NULL. */
|
||||
if (ARITHMETIC_TYPE_P (type) && expr == null_node)
|
||||
{
|
||||
if (fndecl)
|
||||
warning ("passing NULL used for non-pointer %s %P of %qD",
|
||||
errtype, parmnum, fndecl);
|
||||
else
|
||||
warning ("%s to non-pointer type %qT from NULL", errtype, type);
|
||||
}
|
||||
|
||||
/* Warn about assigning a floating-point type to an integer type. */
|
||||
if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
|
||||
&& TREE_CODE (type) == INTEGER_TYPE)
|
||||
{
|
||||
if (fndecl)
|
||||
warning ("passing %qT for %s %P of %qD",
|
||||
TREE_TYPE (expr), errtype, parmnum, fndecl);
|
||||
else
|
||||
warning ("%s to %qT from %qT", errtype, type, TREE_TYPE (expr));
|
||||
}
|
||||
/* And warn about assigning a negative value to an unsigned
|
||||
variable. */
|
||||
else if (TYPE_UNSIGNED (type) && TREE_CODE (type) != BOOLEAN_TYPE)
|
||||
{
|
||||
if (TREE_CODE (expr) == INTEGER_CST && TREE_NEGATED_INT (expr))
|
||||
{
|
||||
if (fndecl)
|
||||
warning ("passing negative value %qE for %s %P of %qD",
|
||||
expr, errtype, parmnum, fndecl);
|
||||
else
|
||||
warning ("%s of negative value %qE to %qT", errtype, expr, type);
|
||||
}
|
||||
|
||||
overflow_warning (expr);
|
||||
|
||||
if (TREE_CONSTANT (expr))
|
||||
expr = fold_if_not_in_template (expr);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
/* Convert value RHS to type TYPE as preparation for an assignment to
|
||||
an lvalue of type TYPE. ERRTYPE is a string to use in error
|
||||
messages: "assignment", "return", etc. If FNDECL is non-NULL, we
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2005-01-30 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
PR c++/19457
|
||||
* g++.dg/warn/conv3.C: New test.
|
||||
|
||||
2005-01-30 Bud Davis <bdavis@gfortran.org>
|
||||
|
||||
PR fortran/19647
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// PR c++/19457
|
||||
|
||||
int i=-1;
|
||||
unsigned int j= ~0; // { dg-bogus "" }
|
Loading…
Reference in New Issue