C1x: Attribute syntax (WG14 N1259)

Joseph Myers

N1233 presents proposals for attribute syntax for C++ which may also be considered in some form for C. Unfortunately those proposal suffer from invention that is incompatible with existing implementations.

N1233 says:

But the statement described in the GCC manual does describe an intended future direction. We suggest that we follow this future direction.

The GCC description, complete with "intended future direction", is what I wrote in January 2001 as part of reverse-engineering the semantics and cleaning up certain parts of the implementation (more details of some issues were added in 2004 following further reverse-engineering).

As such, the future directions there were speculations from 2001 about what I thought might make sense at the time, without much study of how the attributes were used in practice, and those future directions that remain are speculations that no-one has felt worth implementing since then. I no longer believe such incompatible changes to existing semantics to be desirable (in particular, the change to the binding of attributes at the end of declarations picked up in section 4.3 of N1233). I do not think users have paid much attention to this section of the manual or the possibilities of changes mentioned therein, instead preferring the examples of particular attributes and experiments as to what works.

Invention is invention, whenever invented, if it describes something hypothetical and unimplemented. As such, semantics I wrote down in 2001 that were then and remain now incompatible with existing implementations are invention and should be avoided in accordance with the C1X Charter (item 13).

If standardization uses different syntax such as [[ ]] in place of __attribute__ or __declspec, this is also invention, and does not resolve compatibility issues because users will inevitable wish to use macros expanding to C1X syntax or implementation-defined extension syntax depending on the implementation and language version available.

N1233 also explicitly makes an incompatible change to the handling of attributes at the start of declaration specifiers, where in existing implementations they apply to the declaration and in N1233 they apply to the type. The start of declarations is a natural place for attributes with characteristics of storage class specifiers which do apply to a variable or function rather than its type (of the examples in section 3 of N1233, "shared library visibility" and "object code section" would naturally fall in this class), which makes such an incompatible change doubly inappropriate.

Various places where N1233 suggests attributes might be placed appear to be invention in their entirety; I have not examined whether any of those additional locations might conflict with existing implementation practice. I am unsure as to whether the proposed [[ ]] syntax might conflict with existing Objective-C extensions, where expressions may begin with [ and so [[ is a valid pair of tokens at least syntactically.