[libcxx-commits] [libcxx] [libc++] Enable availability based on the compiler instead of __has_extension (PR #84065)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 6 08:14:59 PST 2024
philnik777 wrote:
> > > That means that as it stands, libc++ is not compatible at all with `-pedantic-errors`, since it uses a good number of compiler extensions (and really there’s no way it could go without using compiler extensions).
> >
> >
> > It's not that `-pedantic-errors` disables extensions, it disables `__has_extension` properly reporting extensions.
>
> No, it kind of does disable extensions, which is _why_ `__has_extension` returns `false`. When you specify `-pedantic-errors`, you are saying "any use of an extension is an error" so extensions really aren't available for you. The idea being:
>
> ```
> #if __has_extension(foo)
> #define FOO use_the_extension
> #else
> #define FOO use_the_fallback
> #endif
> ```
>
> should work. If `__has_extension` returns `true` with `-pedantic-errors`, then you'll use the extension and get compile errors as a result instead of using the fallback path.
I get the idea, but it doesn't work in practice. The (at least IMO) moral equivalents `-Werror=pedantic` or `-pedantic -Werror` don't change how `__has_extension` behaves, which means that the behaviour doesn't help you. It's only surprising that your code breaks when someone passes `-pedantic-errors`.
https://github.com/llvm/llvm-project/pull/84065
More information about the libcxx-commits
mailing list