Patch to warn_deprecated_use

Joseph S. Myers jsm@polyomino.org.uk
Thu Sep 9 23:58:00 GMT 2004


This patch fixes two logic errors in warn_deprecated_use meaning it
would ICE on a deprecated nameless type.

(I think this function would be better in c-common.c; it's only used
for C and C++ and in c-common.c it could use %T rather than its own
logic to name types.)

Bootstrapped with no regressions on i686-pc-linux-gnu.  OK to commit?

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
  http://www.srcf.ucam.org/~jsm28/gcc/#c90status - status of C90 for GCC 3.5
    jsm@polyomino.org.uk (personal mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-09-10  Joseph S. Myers  <jsm@polyomino.org.uk>

	* toplev.c (warn_deprecated_use): Correct logic for saying "type"
	in diagnostic.  Don't dereference NULL TYPE_NAME.

testsuite:
2004-09-10  Joseph S. Myers  <jsm@polyomino.org.uk>

	* gcc.dg/deprecated-2.c: New test.

diff -rupN GCC.orig/gcc/testsuite/gcc.dg/deprecated-2.c GCC/gcc/testsuite/gcc.dg/deprecated-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/deprecated-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/deprecated-2.c	2004-09-09 22:19:51.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test __attribute__((deprecated)).  Test types without names.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct { int a; } __attribute__((deprecated)) x; /* { dg-warning "type is deprecated" } */
+typeof(x) y; /* { dg-warning "type is deprecated" } */
diff -rupN GCC.orig/gcc/toplev.c GCC/gcc/toplev.c
--- GCC.orig/gcc/toplev.c	2004-09-09 10:31:55.000000000 +0000
+++ GCC/gcc/toplev.c	2004-09-09 19:16:54.000000000 +0000
@@ -905,11 +905,14 @@ warn_deprecated_use (tree node)
       const char *what = NULL;
       tree decl = TYPE_STUB_DECL (node);
 
-      if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
-	what = IDENTIFIER_POINTER (TYPE_NAME (node));
-      else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
-	       && DECL_NAME (TYPE_NAME (node)))
-	what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
+      if (TYPE_NAME (node))
+	{
+	  if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
+	    what = IDENTIFIER_POINTER (TYPE_NAME (node));
+	  else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
+		   && DECL_NAME (TYPE_NAME (node)))
+	    what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
+	}
 
       if (decl)
 	{
@@ -925,9 +928,9 @@ warn_deprecated_use (tree node)
       else
 	{
 	  if (what)
-	    warning ("type is deprecated");
-	  else
 	    warning ("`%s' is deprecated", what);
+	  else
+	    warning ("type is deprecated");
 	}
     }
 }



More information about the Gcc-patches mailing list