Properly handle C2x attributes on types

Jeff Law
Sat Nov 23 17:14:00 GMT 2019

On 11/21/19 7:42 PM, Joseph Myers wrote:
> attribs.c has code to ignore all scoped attributes appertaining to
> types except when they are part of the definition of that type.
> I think the premise of that code is incorrect, and its presence is a
> bug; such attributes are clearly valid in both C and C++, which
> explicitly specify that attributes in certain syntactic positions
> appertain to a particular type, only for that use of that type and not
> for other uses of the same type specifiers without that attribute
> specified, and while the standard attributes in C2x aren't relevant in
> such contexts, some gnu:: attributes certainly are.  Where some
> attributes are invalid on some types in such contexts, that's a matter
> for the individual attribute handlers to diagnose (or the front end if
> the requirements on a standard attribute in the standard are more
> strict than those of a handler shared with a GNU attribute).
> Thus, this patch removes the bogus code to allow such attributes to be
> used.  Doing so (and adding tests for attributes in such positions)
> shows up that the logic in the C front end for creating the
> c_declarator structures for such attributes put them in the wrong
> place relative to the structures for function and array types, and the
> logic for postfix attributes on a list of declaration specifiers
> failed to handle some cases, so those bugs are also fixed in this
> patch.
> Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit 
> (attribs.c and C++ testsuite changes)?
> gcc:
> 2019-11-22  Joseph Myers  <>
> 	* attribs.c (decl_attributes): Do not ignore C++11 attributes on
> 	types.
> gcc/c:
> 2019-11-22  Joseph Myers  <>
> 	* c-tree.h (struct c_declarator): Use a structure for id member.
> 	* c-decl.c (grokdeclarator): Extract attributes from cdk_id
> 	declarators at the start, not when handling individual declarators
> 	later.  Use instead of
> 	(grokfield): Use instead of
> 	(build_id_declarator): Set and
> 	(finish_declspecs): Handle postfix attributes in case of typedef
> 	name or typeof used.
> 	* c-parser.c (c_parser_direct_declarator)
> 	(c_parser_direct_declarator_inner): Place declarator for
> 	attributes inside that for function or array, not outside.  Set
> for identifiers.
> 	(c_parser_parameter_declaration): Use instead of
> 	* gimple-parser.c (c_parser_gimple_declaration): Use
> 	instead of
> gcc/testsuite:
> 2019-11-22  Joseph Myers  <>
> 	* gcc.dg/gnu2x-attrs-1.c: Do not expect message about attributes
> 	appertaining to types.
> 	* gcc.dg/gnu2x-attrs-2.c: New test.
> 	* g++.dg/cpp0x/gen-attrs-1.C, g++.dg/cpp0x/gen-attrs-22.C,
> 	g++.dg/cpp0x/gen-attrs-4.C, g++.dg/cpp0x/lambda/lambda-attr1.C:
> 	Update expected diagnostics.

More information about the Gcc-patches mailing list