[cfe-dev] [PATCH] New syntax and functionality for __has_attribute
dblaikie at gmail.com
dblaikie at gmail.com
Sat Jan 11 10:49:48 PST 2014
I'm not sure this is necessary - do any compilers (including different
versions of clang itself, which I believe is the main use of has_attribute)
support the same attribute but in differing syntaxes? Otherwise it just
seems an invariant of the attribute and not something that would need
compile time tests for because it won't vary by compilation
On Friday, January 10, 2014 2:11:31 PM, Aaron Ballman <
aaron at aaronballman.com> wrote:
The __has_attribute feature macro is fantastic in many respects, but
is lacking the ability to determine whether a specific attribute
syntax is available or not. Instead, it currently checks whether the
attribute is known within the compilation target, and nothing more.
This can cause problems because not all attributes are applied in the
same way.
Consider dllexport as a contrived example:
#if __has_attribute(dllexport)
void foo(void) __attribute__((dllexport));
#endif
This code looks fine, but is actually broken because clang only
supports __declspec(dllexport) and not __attribute__((dllexport)), and
__declspec must precede the declaration.
The attached patch implements new syntax for __has_attribute while
retaining backwards compatibility. It allows you to specify exactly
which attribute syntax you desire. If no specific syntax is specified,
it behaves as it always has.
The supported forms are:
__has_attribute(__attribute__((ident))) // GNU-style
__has_attribute(__declspec(ident)) // MS-style
__has_attribute([[ident]]) // C++11-style
__has_attribute([[scope::ident]]) // C++11-style
__has_attribute(ident) // Keywords, or "don't care"
Note that attribute arguments are not supported by design -- they
really don't make any sense in the context of a feature macro.
~Aaron
_______________________________________________
cfe-commits mailing list
cfe-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140111/b3724630/attachment.html>
More information about the cfe-dev
mailing list