This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFC: PR c/36892: Support __attribute__((deprecated("text string")))
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 15 Sep 2008 11:39:40 -0700
- Subject: RFC: PR c/36892: Support __attribute__((deprecated("text string")))
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
This patch adds an optional string for deprecated attribute. I got
[hjl@gnu-6 770]$ cat y.c
__attribute__ ((deprecated("is replaced by \"new_bar\""))) int bar ();
void
foo ()
{
bar ();
}
[hjl@gnu-6 770]$ cat z.c
__attribute__ ((deprecated)) int bar ();
void
foo ()
{
bar ();
}
[hjl@gnu-6 770]$ make
/export/build/gnu/gcc-work/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-work/build-x86_64-linux/gcc/ -O2 -S -o y.s y.c
y.c: In function âfooâ:
y.c:6: warning: âbarâ is deprecated (declared at y.c:1): is replaced by
"new_bar"
/export/build/gnu/gcc-work/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc-work/build-x86_64-linux/gcc/ -O2 -S -o z.s z.c
z.c: In function âfooâ:
z.c:6: warning: âbarâ is deprecated (declared at z.c:1)
[hjl@gnu-6 770]$
Does it make senses?
Thanks.
H.J.
----
2008-09-15 H.J. Lu <hongjiu.lu@intel.com>
PR c/36892
* c-common.c (c_common_attribute_table): Allow 0 or 1 argument
for deprecated.
(handle_deprecated_attribute): Allow a message.
* toplev.c (warn_deprecated_use): Print a message if it is
specified.
--- gcc/c-common.c.old 2008-09-10 09:02:48.000000000 -0700
+++ gcc/c-common.c 2008-09-15 11:33:46.000000000 -0700
@@ -823,7 +823,7 @@ const struct attribute_spec c_common_att
to prevent its usage in source code. */
{ "no vops", 0, 0, true, false, false,
handle_novops_attribute },
- { "deprecated", 0, 0, false, false, false,
+ { "deprecated", 0, 1, false, false, false,
handle_deprecated_attribute },
{ "vector_size", 1, 1, false, true, false,
handle_vector_size_attribute },
@@ -6471,13 +6471,21 @@ handle_novops_attribute (tree *node, tre
static tree
handle_deprecated_attribute (tree *node, tree name,
- tree ARG_UNUSED (args), int flags,
+ tree args, int flags,
bool *no_add_attrs)
{
tree type = NULL_TREE;
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 (DECL_P (*node))
{
tree decl = *node;
--- gcc/toplev.c.old 2008-09-11 16:48:39.000000000 -0700
+++ gcc/toplev.c 2008-09-15 11:28:11.000000000 -0700
@@ -899,15 +899,29 @@ emit_debug_global_declarations (tree *ve
void
warn_deprecated_use (tree node)
{
+ tree attr;
+ const char *msg;
+
if (node == 0 || !warn_deprecated_decl)
return;
+ attr = lookup_attribute ("deprecated", DECL_ATTRIBUTES (node));
+ if (attr)
+ msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
+ else
+ msg = NULL;
+
if (DECL_P (node))
{
expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
- warning (OPT_Wdeprecated_declarations,
- "%qD is deprecated (declared at %s:%d)",
- node, xloc.file, xloc.line);
+ if (msg)
+ warning (OPT_Wdeprecated_declarations,
+ "%qD is deprecated (declared at %s:%d): %s",
+ node, xloc.file, xloc.line, msg);
+ else
+ warning (OPT_Wdeprecated_declarations,
+ "%qD is deprecated (declared at %s:%d)",
+ node, xloc.file, xloc.line);
}
else if (TYPE_P (node))
{
@@ -928,20 +942,46 @@ warn_deprecated_use (tree node)
expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (decl));
if (what)
- warning (OPT_Wdeprecated_declarations,
- "%qs is deprecated (declared at %s:%d)", what,
- xloc.file, xloc.line);
+ {
+ if (msg)
+ warning (OPT_Wdeprecated_declarations,
+ "%qs is deprecated (declared at %s:%d): %s",
+ what, xloc.file, xloc.line, msg);
+ else
+ warning (OPT_Wdeprecated_declarations,
+ "%qs is deprecated (declared at %s:%d)", what,
+ xloc.file, xloc.line);
+ }
else
- warning (OPT_Wdeprecated_declarations,
- "type is deprecated (declared at %s:%d)",
- xloc.file, xloc.line);
+ {
+ if (msg)
+ warning (OPT_Wdeprecated_declarations,
+ "type is deprecated (declared at %s:%d): %s",
+ xloc.file, xloc.line, msg);
+ else
+ warning (OPT_Wdeprecated_declarations,
+ "type is deprecated (declared at %s:%d)",
+ xloc.file, xloc.line);
+ }
}
else
{
if (what)
- warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
+ {
+ if (msg)
+ warning (OPT_Wdeprecated_declarations, "%qs is deprecated: %s",
+ what, msg);
+ else
+ warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
+ }
else
- warning (OPT_Wdeprecated_declarations, "type is deprecated");
+ {
+ if (msg)
+ warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
+ msg);
+ else
+ warning (OPT_Wdeprecated_declarations, "type is deprecated");
+ }
}
}
}