[llvm-bugs] [Bug 52545] New: Need __has_pragma

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 18 05:52:09 PST 2021


            Bug ID: 52545
           Summary: Need __has_pragma
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: scanon at apple.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211118/94493020/attachment.html>

More information about the llvm-bugs mailing list