PR c++/19457
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 31 Jan 2005 01:17:11 +0000 (01:17 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 31 Jan 2005 01:17:11 +0000 (01:17 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94463 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/name-lookup.c
gcc/cp/semantics.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/conv3.C [new file with mode: 0644]

index dbb8551..1902735 100644 (file)
@@ -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
index 4828b9c..599aecf 100644 (file)
@@ -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:
index 0594dbe..ced845b 100644 (file)
@@ -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);
index 3690e87..bb40e53 100644 (file)
@@ -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
         {
index 466587e..c0e68d1 100644 (file)
@@ -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;
 }
index ff960a9..53a48d1 100644 (file)
@@ -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
index 37bcc5b..c90f671 100644 (file)
@@ -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
diff --git a/gcc/testsuite/g++.dg/warn/conv3.C b/gcc/testsuite/g++.dg/warn/conv3.C
new file mode 100644 (file)
index 0000000..5900c3a
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/19457
+
+int i=-1;
+unsigned int j= ~0; // { dg-bogus "" }