Skip to content

Need __has_pragma #51887

@llvmbot

Description

@llvmbot
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyenhancementImproving things as opposed to bug fixing, e.g. new or missing featureextension:clang

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions