[libcxx-commits] [libcxx] [libcxx] Undefine all supported C math functions (PR #94533)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 4 09:47:20 PDT 2024
https://github.com/ldionne commented:
I think I agree with @philnik777 's comments about this being needed for every C library function.
Basically, we have to choose whether libc++ works on top of a conforming C Standard Library per the C Standard, or whether we require C++ friendliness in a C Standard Library for it to be usable with libc++.
If we support an arbitrary conforming C Standard Library, then per 7.1.4 it does seem like they are allowed to define functions as macros, which is extremely unfriendly to C++ due to namespaces amongst other things. I've come across this issue (with `memcpy` for example) several times when porting libc++ to new platforms.
So far, what I've always done was to ask the underlying C library to stop using macros because that is C++-unfriendly. However, it might be reasonable for libc++ to support that.
Doing this correctly in the general case is going to be non-trivial, though, since it basically means that we can't blindly reuse names from the C Standard Library anymore. For example, `strxfrm` isn't defined anywhere by libc++, we just reuse it from the C stdlib:
```c++
// <cstring>
namespace std {
using ::strxfrm;
}
```
If we wanted to work in spite of ยง7.1.4, we'd basically have to `#undef strxfrm` and then define it ourselves as a function. I believe the logical conclusion here is that we basically can't reuse anything from the C Standard Library, we'd have to implement everything ourselves.
This makes me wonder whether that is a viable approach. Thoughts?
https://github.com/llvm/llvm-project/pull/94533
More information about the libcxx-commits
mailing list