toplev.c (warn_deprecated_use): Correct logic for saying "type" in diagnostic.
authorJoseph Myers <jsm@polyomino.org.uk>
Fri, 10 Sep 2004 10:54:25 +0000 (11:54 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 10 Sep 2004 10:54:25 +0000 (11:54 +0100)
* toplev.c (warn_deprecated_use): Correct logic for saying "type"
in diagnostic.  Don't dereference NULL TYPE_NAME.

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

From-SVN: r87289

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/deprecated-2.c [new file with mode: 0644]
gcc/toplev.c

index 72d1e46fbaf2ccb835ce0547c38bf4a6352a43d4..74815048c0ce2be6325ff0b2dd93d1780c8b4b7b 100644 (file)
@@ -1,3 +1,8 @@
+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.
+
 2004-09-10  Kazu Hirata  <kazu@cs.umass.edu>
 
        * c-common.c, c-pch.c, defaults.h, lambda-code.c, passes.c,
index 1dbc50a01d5eaed1e6a520605bdd3c008a9e4885..c33d260b5b3cbf70a53b774e06571b0b23c6516d 100644 (file)
@@ -1,3 +1,7 @@
+2004-09-10  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       * gcc.dg/deprecated-2.c: New test.
+
 2004-09-09  James E Wilson  <wilson@specifixinc.com>
 
        * gcc.dg/init-vec-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/deprecated-2.c b/gcc/testsuite/gcc.dg/deprecated-2.c
new file mode 100644 (file)
index 0000000..c4ca8a2
--- /dev/null
@@ -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" } */
index c3cae64b296b23d82a9cfc43b93deb08a336db1c..79094e2e039f2ed69546fe490bf4c72f4d12579a 100644 (file)
@@ -900,11 +900,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)
        {
@@ -920,9 +923,9 @@ warn_deprecated_use (tree node)
       else
        {
          if (what)
-           warning ("type is deprecated");
-         else
            warning ("`%s' is deprecated", what);
+         else
+           warning ("type is deprecated");
        }
     }
 }