Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22233

Can `__has_cpp_attribute` be used as a reliable way to check attribute support?

$
0
0

I stumbled upon a disappointing behavior with GCC 9 regarding [[likely]]/[[unlikely]] attributes support and __has_cpp_attribute.

GCC 9 have introduced an experimental support for [[likely]]/[[unlikely]] attributes. The attributes are available even if compiled with /std:c++17. But if you try to use them in if statement as in the working draft it will fail to compile (small code example).

And in GCC 10 the same code seems to be working well.

The problem here is that it seems like we still don't have a way to check if an attribute can be used in code or not despite having __has_cpp_attribute feature in the language. That's because it only tells whether an attribute is available or not, not whether it's fully implemented or not.

Before discovering this problem I had checks using __has_cpp_attribute (example) in my code. Right now I'm adding an additional check for the GCC version there (something like __GNUC__ >= 9 && __GNUC__ < 10), but it's definitely a crutch.

Can I check more reliably that an attribute is implemented and ready to use?

What __has_cpp_attribute can be used for?

Maybe I'm missing something?


Viewing all articles
Browse latest Browse all 22233

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>