-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Description
Bugzilla Link | 52545 |
Version | unspecified |
OS | All |
Reporter | LLVM Bugzilla Contributor |
CC | @AaronBallman,@zygoloid |
Extended Description
We have __has_feature and __has_attribute and a number of other variants so that code can take advantage of new features while still functioning with older clang versions. We should also have __has_pragma for the same reason.
In particular, I was recently bitten by trying to use the clang fp reassociate(on) pragma, which is available in clang-11+; rather than producing an "unknown pragma" warning, older clangs produce the error "invalid option 'reassociate'; expected contract".
An alternative solution (which would have worked in my case) would be to have unknown pragma options always be a warning instead of an error, but in general it's a better option to have __has_pragma, because it gives the user the building block to fallback on a different solution or to produce an error in cases where that's more appropriate.
I think a minimum-viable __has_pragma would take a string argument that's the entire pragma body and produce a result of 1 if the string is an accepted pragma for the current target.