aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-15 00:06:30 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-15 00:06:30 +0000
commit2cc94aa8d817bab3af6ff5b41135ad30ee50f09b (patch)
treeb815f47b6482a5df0d39aa4b4e98970218369860 /gcc/c-family
parent1a4ec3250596b03e1b2edcfbc9d903c1f189f077 (diff)
downloadgcc-2cc94aa8d817bab3af6ff5b41135ad30ee50f09b.zip
gcc-2cc94aa8d817bab3af6ff5b41135ad30ee50f09b.tar.gz
gcc-2cc94aa8d817bab3af6ff5b41135ad30ee50f09b.tar.bz2
Support C2x [[deprecated]] attribute.
This patch adds support for the C2x [[deprecated]] attribute. All the actual logic for generating warnings can be identical to the GNU __attribute__ ((deprecated)), as can the attribute handler, so this is just a matter of wiring things up appropriately and adding the checks specified in the standard. Unlike for C++, this patch gives "deprecated" an entry in a table of standard attributes rather than remapping it internally to the GNU attribute, as that seems a cleaner approach to me. Specifically, the only form of arguments to the attribute permitted in the standard is (string-literal); empty parentheses are not permitted in the case of no arguments, and a string literal (which includes concatenated adjacent string literals, because concatenation is an earlier phase of translation) cannot have further redundant parentheses around it. For the case of empty parentheses, this patch makes the C parser disallow them for all known attributes using the [[]] syntax, as done for C++. For string literals (where the C++ front end is missing the check to avoid redundant parentheses, 92521 filed for that issue), a special case is inserted in the C parser. A known issue that I think can be addressed later as a bug fix is that the warnings for the attribute being ignored in certain cases (attribute declarations, statements, most uses on types) ought to be pedwarns, as those usages are constraint violations. Bad handling of wide string literals with this attribute is also a pre-existing bug (91182 - although that's filed as a C++ bug, the code in question is language-independent, in tree.c). Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (std_attribute_table): New. (c_init_decl_processing): Register attributes from std_attribute_table. * c-parser.c (c_parser_attribute_arguments): Add arguments require_string and allow_empty_args. All callers changed. (c_parser_std_attribute): Set require_string argument for "deprecated" attribute. gcc/c-family: * c-attribs.c (handle_deprecated_attribute): Remove static. * c-common.h (handle_deprecated_attribute): Declare. gcc/testsuite: * gcc.dg/c2x-attr-deprecated-1.c, gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-deprecated-3.c: New tests. From-SVN: r278268
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-attribs.c4
-rw-r--r--gcc/c-family/c-common.h1
3 files changed, 7 insertions, 3 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index f4fdccc..571cf2b 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2019-11-15 Joseph Myers <joseph@codesourcery.com>
+
+ * c-attribs.c (handle_deprecated_attribute): Remove static.
+ * c-common.h (handle_deprecated_attribute): Declare.
+
2019-11-14 Joseph Myers <joseph@codesourcery.com>
* c-lex.c (lex_charconst): Make CPP_UTF8CHAR constants unsigned
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index c62cebf..18b829f 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -115,8 +115,6 @@ static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
static tree handle_tm_attribute (tree *, tree, tree, int, bool *);
static tree handle_tm_wrap_attribute (tree *, tree, tree, int, bool *);
static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
-static tree handle_deprecated_attribute (tree *, tree, tree, int,
- bool *);
static tree handle_vector_size_attribute (tree *, tree, tree, int,
bool *);
static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
@@ -3468,7 +3466,7 @@ handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
/* Handle a "deprecated" attribute; arguments as in
struct attribute_spec.handler. */
-static tree
+tree
handle_deprecated_attribute (tree *node, tree name,
tree args, int flags,
bool *no_add_attrs)
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 80a8c9f..ad40c15 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1357,6 +1357,7 @@ extern void warn_for_multistatement_macros (location_t, location_t,
/* In c-attribs.c. */
extern bool attribute_takes_identifier_p (const_tree);
+extern tree handle_deprecated_attribute (tree *, tree, tree, int, bool *);
extern tree handle_unused_attribute (tree *, tree, tree, int, bool *);
extern int parse_tm_stmt_attr (tree, int);
extern int tm_attr_to_mask (tree);