[cfe-dev] __has_attribute behavior with target-specific attributes

Aaron Ballman aaron at aaronballman.com
Fri Dec 6 09:33:49 PST 2013


Currently, the __has_attribute feature merely looks to see whether the
given attribute name is known. It does not care whether the attribute
is known for a particular target. So, for instance, the mips16
attribute is only known to the Mips target, but
__has_attribute(mips16) will return 1 for x86. There is at least one
case in the wild (with chrome tsan) where the assumption was that
__has_attribute was target-aware.

After discussing this on IRC, the general consensus was that the
current behavior is less than desirable because it requires the author
to write #if target && __has_attribute which kind of defeats the
purpose of __has_attribute in the first place.

Work can be done to make __has_attribute target-aware, however, it
would then make __has_attribute behave differently than __has_builtin
(for example), so it may not be a desirable direction. It's also a
functional change to a shipping feature. So I am proceeding with
caution.

As I see it, there are three options:

1) Change __has_attribute to be target-aware, update the documentation
regarding the new functionality.
2) Leave the feature as-is, and update the documentation to be clear
that __has_attribute is not target-aware.
3) Leave everything as it stands (including documentation) so we can
change our minds in the future. I don't much care for this option.

I am wondering what the proper direction to proceed is.

Thanks!

~Aaron



More information about the cfe-dev mailing list