Commit 2eca4ff4 authored by Joseph Myers's avatar Joseph Myers
Browse files

c: C2x attributes fixes and updates

Implement some changes to the currently supported C2x standard
attributes that have been made to the specification since they were
first implemented in GCC, and some consequent changes:

* maybe_unused is now supported on labels.  In fact that was already
  accidentally supported in GCC as a result of sharing the
  implementation with __attribute__ ((unused)), but needed to be
  covered in the tests.

* As part of the support for maybe_unused on labels, its
  __has_c_attribute value changed.

* The issue of maybe_unused accidentally being already supported on
  labels showed up the lack of tests for other standard attributes
  being incorrectly applied to labels; add such tests.

* Use of fallthrough or nodiscard attributes on labels already
  properly resulted in a pedwarn.  For the deprecated attribute,
  however, there was only a warning, and the wording "'deprecated'
  attribute ignored for 'void'" included an unhelpful "for 'void'".
  Arrange for the case of the deprecated attribute on a label to be
  checked for separately and result in a pedwarn.  As with
  inappropriate uses of fallthrough (see commit
  6c80b1b5), it seems reasonable for
  this pedwarn to apply regardless of whether [[]] or __attribute__
  was used and regardless of whether C or C++ is being compiled.

* Attributes on case or default labels (the standard syntax supports
  attributes on all kinds of labels) were quietly ignored, whether or
  not appropriate for use in such a context, because they weren't
  passed to decl_attributes at all.  (Note where I'm changing the
  do_case prototype that such a function is actually only defined in
  the C front end, not for C++, despite the declaration being in
  c-common.h.)

* A recent change as part of the editorial review in preparation for
  the C2x CD ballot has changed the __has_c_attribute value for
  fallthrough to 201910 to reflect when that attribute was actually
  voted into the working draft.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c-family/
	* c-attribs.cc (handle_deprecated_attribute): Check and pedwarn
	for LABEL_DECL.
	* c-common.cc (c_add_case_label): Add argument ATTRS.  Call
	decl_attributes.
	* c-common.h (do_case, c_add_case_label): Update declarations.
	* c-lex.cc (c_common_has_attribute): For C, produce a result of
	201910 for fallthrough and 202106 for maybe_unused.

gcc/c/
	* c-parser.cc (c_parser_label): Pass attributes to do_case.
	* c-typeck.cc (do_case): Add argument ATTRS.  Pass it to
	c_add_case_label.

gcc/testsuite/
	* gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-fallthrough-2.c,
	gcc.dg/c2x-attr-maybe_unused-1.c, gcc.dg/c2x-attr-nodiscard-2.c:
	Add tests of attributes on labels.
	* gcc.dg/c2x-has-c-attribute-2.c: Update expected results for
	maybe_unused and fallthrough.
parent 26aafae4
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment