This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, attribute(deprecated)] fix PR43797.


this:

typedef int INT1 __attribute__((deprecated("No INT1")));
INT1 f1 (void) __attribute__((deprecated("No f1")));
INT1 f2 (void) __attribute__((deprecated));

void func (void)
{
  f1();
  f2();
}

should print :
'f1' is deprecated .....: No f1
'f2' is deprecated .....

but with trunk the second message is incorrectly:
'f2' is deprecated ..... : No INT1.

----

the following has been bootstrapped & regtested on i686-apple-darwin9 and checked to give the correct answer with:
xgcc, g++, xgcc -x objective-c and xgcc -x objective-c++


(g++/ObjC++ modulo the issues of duplicated warnings, which is a different PR)

I have only attached a testcase to "C" since the principal change is in common code.

OK for trunk?
Iain

----

gcc/

	PR c/43797
	* toplev.c: Handle deprecated attribute search consistently.

gcc/c-family

PR c/43797
* c-common.c: Attach __attribute__(deprecated), even when there is no deprecation
advice message.


testsuite/

	PR c/43797
	* gcc.dg/pr43797.c: New.

===
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c	(revision 162282)
+++ gcc/toplev.c	(working copy)
@@ -867,15 +867,16 @@ warn_deprecated_use (tree node, tree attr)
 	{
 	  tree decl = TYPE_STUB_DECL (node);
 	  if (decl)
-	    attr = lookup_attribute ("deprecated",
-				     TYPE_ATTRIBUTES (TREE_TYPE (decl)));
+	    attr = TYPE_ATTRIBUTES (TREE_TYPE (decl));
+	  else
+	    attr = TYPE_ATTRIBUTES (node);
 	}
     }

   if (attr)
     attr = lookup_attribute ("deprecated", attr);

- if (attr)
+ if (attr && TREE_VALUE (attr) && TREE_VALUE (TREE_VALUE (attr)))
msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
else
msg = NULL;
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c (revision 162282)
+++ gcc/c-family/c-common.c (working copy)
@@ -7115,13 +7115,8 @@ handle_deprecated_attribute (tree *node, tree name
int warn = 0;
tree what = NULL_TREE;


-  if (!args)
-    *no_add_attrs = true;
-  else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
-    {
-      error ("deprecated message is not a string");
-      *no_add_attrs = true;
-    }
+  if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
+    error ("deprecated message is not a string");

if (DECL_P (*node))
{
Index: gcc/testsuite/gcc.dg/pr43797.c
===================================================================
--- gcc/testsuite/gcc.dg/pr43797.c (revision 0)
+++ gcc/testsuite/gcc.dg/pr43797.c (revision 0)
@@ -0,0 +1,13 @@
+/* pr 43797 */
+/* dg-do compile */
+
+typedef int INT1 __attribute__((deprecated("No INT1")));
+INT1 f1 (void) __attribute__((deprecated("No f1")));
+INT1 f2 (void) __attribute__((deprecated));
+
+void func (void)
+{
+ f1(); /* { dg-warning "'f1' is deprecated .declared at \[^\\)\]*.: No f1" "f1" } */
+ f2(); /* { dg-bogus "'f2' is deprecated .declared at \[^\\)\]*.: No INT1" "f2-wrong deprecation message" } */
+ /* { dg-warning "'f2' is deprecated .declared at \[^\\)\]*." "f2" { target *-*-* } 11 } */
+}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]