Support C2x [[deprecated]] attribute

Programming / Compilers / GCC - jsm28 [138bc75d-0d04-0410-961f-82ee72b054a4] - 15 November 2019 00:06 EST

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.

- 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.

- c-attribs.c (handle_deprecated_attribute): Remove static.
- c-common.h (handle_deprecated_attribute): Declare.

- gcc.dg/c2x-attr-deprecated-1.c, gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-deprecated-3.c: New tests.

23c6a99f983 Support C2x [[deprecated]] attribute.
gcc/c-family/ChangeLog | 5 ++
gcc/c-family/c-attribs.c | 4 +-
gcc/c-family/c-common.h | 1 +
gcc/c/ChangeLog | 10 +++
gcc/c/c-decl.c | 12 ++++
gcc/c/c-parser.c | 28 +++++++--
gcc/testsuite/ChangeLog | 5 ++
gcc/testsuite/gcc.dg/c2x-attr-deprecated-1.c | 91 ++++++++++++++++++++++++++++
gcc/testsuite/gcc.dg/c2x-attr-deprecated-2.c | 25 ++++++++
gcc/testsuite/gcc.dg/c2x-attr-deprecated-3.c | 11 ++++
10 files changed, 185 insertions(+), 7 deletions(-)


  • Share