[libcxx-commits] [libcxx] [libcxxabi] [libc++][RFC] Always define internal feature test macros (PR #89178)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 9 06:09:29 PDT 2024
ldionne wrote:
> I'm more ok with changing to 1 or 0 than I am removing the negative feature test names. Did the `<__availability>` bugs you referenced use negative feature test names? Those are important, and I would consider blocking this change if it meant using positive feature tests.
>
> Let me know if I need to do a better job of explaining why positive names are less desirable than negative ones.
>
I would like to better understand this aspect. My understanding is that we've been using negative "configuration macros" mainly because when we use `#ifdef` as a branching mechanism, it's more natural that the state where nothing is defined is the default configuration of the library. And since most (but not all) of our "configuration macros" are removing things from the default configuration (e.g. `-fno-exceptions`, `-fno-rtti`, etc), it makes sense that these macros would be negative.
However, note that this pattern doesn't always make sense. For example, @philnik777 pointed out to me that we have `_LIBCPP_HAS_NO_ASAN`. Our default configuration of the library doesn't assume ASAN, and so IMO it looks weird that our default configuration would be what's inside `#ifndef _LIBCPP_HAS_NO_ASAN`. Instead, it would make more sense to say `#ifdef _LIBCPP_HAS_ASAN`.
This patch basically puts all the configuration macros on the "same level" and uses a consistent mechanism to handle all of them.
There's still the question of whether we want to have
```c++
#if !_LIBCPP_HAS_NO_EXCEPTIONS
...
#endif
```
versus
```c++
#if _LIBCPP_HAS_EXCEPTIONS
...
#endif
```
IMO, avoiding the double-negative in this case makes things a lot easier to understand.
To summarize: I agree that negative macros make more sense in a `#ifndef` world, however I think their benefit is lost when we move to `0-1` macros instead. I'd love to know your thoughts on that.
https://github.com/llvm/llvm-project/pull/89178
More information about the libcxx-commits
mailing list