aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2005-01-31 01:17:11 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2005-01-31 01:17:11 +0000
commit6fc98adf766d2ce6179d8d7a165d101c8fc00391 (patch)
tree5e527e579dc243e4d53a56e537c89e568908ccf0 /gcc/cp
parentef3f52283738edb9bf764801c706a00ceb0d45ce (diff)
downloadgcc-6fc98adf766d2ce6179d8d7a165d101c8fc00391.zip
gcc-6fc98adf766d2ce6179d8d7a165d101c8fc00391.tar.gz
gcc-6fc98adf766d2ce6179d8d7a165d101c8fc00391.tar.bz2
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
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog14
-rw-r--r--gcc/cp/call.c42
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/name-lookup.c8
-rw-r--r--gcc/cp/semantics.c7
-rw-r--r--gcc/cp/typeck.c51
6 files changed, 64 insertions, 59 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index dbb8551..1902735 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4828b9c..599aecf 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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:
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 0594dbe5c..ced845b 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -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);
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 3690e87..bb40e53 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -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
{
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 466587e..c0e68d1 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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;
}
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index ff960a9..53a48d1 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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