[cfe-dev] Possible bug with __has_cpp_attribute

Aaron Ballman aaron at aaronballman.com
Wed May 6 05:21:52 PDT 2015


On Wed, May 6, 2015 at 4:28 AM, Kal <b17c0de at gmail.com> wrote:
> Hi,
> The following seems like a clang bug.
>
> You can't use __has_cpp_attribute with namespaces in a header that is
> included from C. For example:
> #if __has_cpp_attribute(clang::fallthrough)
>    ...
> #endif
>
> Yields:
> error: builtin feature check macro requires a parenthesized identifier.
>
> Shouldn't __has_cpp_attribute() evaluate to 0 for C programs?

That's debatable. I would say it should be an error for C programs to
refer to __has_cpp_attribute because it should not be a predefined
macro there. I think the bug is that __has_cpp_attribute isn't flag as
being available only for C++. Then you could use the canonical
#if/#elif block for C++ attribute feature testing, without needing the
__cplusplus bit in yours.

~Aaron

>
> I worked around the issue with something like:
>
> #ifndef __has_cpp_attribute
> #define __has_cpp_attribute(x) 0
> #elif defined(__clang__) && !defined(__cplusplus)
> #pragma clang diagnostic push
> #pragma clang diagnostic ignored "-Wbuiltin-macro-redefined"
> #define __has_cpp_attribute(x) 0
> #pragma clang diagnostic pop
> #endif
>
> Is there a better way?
>
> -Kal
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list