[PATCH] Generalized attribute support

Aaron Ballman aaron at aaronballman.com
Wed Jan 15 06:43:43 PST 2014


On Tue, Jan 14, 2014 at 8:47 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Tue, Jan 14, 2014 at 5:23 PM, Alp Toker <alp at nuanti.com> wrote:
>>
>> This patch generalizes C++11 attributes for use in C and C-like dialects,
>> and additionally enables the new syntax as an extension to C11.
>
>
> Why do you allow this by default in C11? And conversely, why not in C90 /
> C99?
>
> If we're going to allow these anywhere by default, C++98 would seem like a
> good place to start. I don't believe they introduce any ambiguities outside
> of Objective-C(++), and we already disambiguate those cases. (There's an
> ambiguity with lambdas, but we don't need to address that until/unless we
> allow lambdas in C++98.)

I don't think they should be allowed by default; I think it should be
a feature that's turned on manually by the user. Otherwise, we're
encroaching on other language's feature-space.

>
>>
>> All features are carried forward from C++11, including usage on
>> declarations, attributed statements, scoped attribute names, GNU attribute
>> aliases and the clang-specific attribute namespace.
>>
>> A new feature detection macro is provided, breaking from the usual c/cxx
>> prefix convention in order to facilitate portable detection in C++ and C
>> modes:
>>
>> __has_feature(attributes) - 1 in C++11, otherwise 0.
>> __has_extension(attributes) - 1 in C++11 and C11, otherwise 0.
>
>
> This is already available as __has_feature(cxx_attributes); using
> __has_extension(cxx_attributes) in C would seem to be the right approach
> here (we're allowing C++ attributes as an extension in C). This is what we
> already do for C99 and C11 features which we accept in C++.

Agreed.

~Aaron



More information about the cfe-commits mailing list