[libcxx-commits] [libcxx] [libc++] Fix acceptance of convertible-to-{float, double, long double} in std::isnan() and std::isinf() (PR #98952)
Robin Caloudis via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jul 21 02:19:56 PDT 2024
robincaloudis wrote:
With my changes, there is a conflicting declaration error of `isnan` and `isinf` between headers of `libc++`(libcxx of the llvm project) libstdc++ (default standard library of Clang on Linux) when running any of the cxx03 jobs. In `libstdc++`, both functions are guarded by preprocessor directives as [`/* isnan conflicts with C++11. */`](https://github.com/bminor/glibc/blob/256574679feb0204ac859367fdbf4d91aff45d0a/math/bits/mathcalls.h#L224) and [`/* isinf conflicts with C++11. */`](https://github.com/bminor/glibc/blob/256574679feb0204ac859367fdbf4d91aff45d0a/math/bits/mathcalls.h#L187). As we have `__cplusplus <= 199711L` in place for cxx03 jobs using `-std=c++03`, `isnan` and `isinf` are included. This more or less explains why we have a broken cxx03 job.
However, this does not explain the big picture to me:
- Why are headers from both `libstdc++` and `libc++` end up in the same compilation unit? From what I understand, Clang needs to either use the headers of `libstdc++` or `libc++` it in order to produce software that is compatible with the rest of the system
- A close look at the executed command shows us that the `-nostdlib++` and `-nostdinc++` is in place. I guess that this flag in the Clang frontend instructs the compiler not to use the standard system libraries as well as the corresponding headers. So the compilation unit needs to be „fully self contained“. Now I am even more confused as I do not understand how `/usr/include/x86_64-linux-gnu/bits/mathcalls.h` can end up in the compilation unit when `-nostdinc++` is in place.
To me it seems like `-I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1` (part of `libc++`) somehow depends on `/usr/include/x86_64-linux-gnu/bits/mathcalls.h` (part of`libstdc++`). Unfortunately, I have not found a way to proof my assumptions and probably lack some details. Could anyone give me a hint on what is going on under the hood?
Error output for `Build and Test libc++ / stage1 (generic-cxx03, clang-19, clang++-19)`
```
# executed command: /usr/bin/clang++-19 /home/runner/_work/llvm-project/llvm-project/libcxx/test/std/containers/unord/unord.multimap/key_eq.pass.cpp -pthread --target=x86_64-unknown-linux-gnu -nostdinc++ -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1 -I /home/runner/_work/llvm-project/llvm-project/libcxx/test/support -std=c++03 -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety -Wuser-defined-warnings -lc++experimental -nostdlib++ -L /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/lib -Wl,-rpath,/home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/lib -lc++ -latomic -o /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/test/std/containers/unord/unord.multimap/Output/key_eq.pass.cpp.dir/t.tmp.exe
# .---command stderr------------
# | In file included from /home/runner/_work/llvm-project/llvm-project/libcxx/test/std/containers/unord/unord.multimap/key_eq.pass.cpp:17:
# | In file included from /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/unordered_map:591:
# | In file included from /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__hash_table:43:
# | In file included from /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/cmath:318:
# | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/math.h:422:20: error: target of using declaration conflicts with declaration already in scope
# | 422 | using std::__math::isinf;
# | | ^
# | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__math/traits.h:86:83: note: target of using declaration
# | 86 | _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(double __x) _NOEXCEPT {
# | | ^
# | /usr/include/x86_64-linux-gnu/bits/mathcalls.h:177:23: note: conflicting declaration
# | 177 | __MATHDECL_ALIAS (int,isinf,, (_Mdouble_ __value), isinf)
# | | ^
# | In file included from /home/runner/_work/llvm-project/llvm-project/libcxx/test/std/containers/unord/unord.multimap/key_eq.pass.cpp:17:
# | In file included from /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/unordered_map:591:
# | In file included from /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__hash_table:43:
# | In file included from /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/cmath:318:
# | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/math.h:426:20: error: target of using declaration conflicts with declaration already in scope
# | 426 | using std::__math::isnan;
# | | ^
# | /home/runner/_work/llvm-project/llvm-project/build/generic-cxx03/include/c++/v1/__math/traits.h:110:83: note: target of using declaration
# | 110 | _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(double __x) _NOEXCEPT {
# | | ^
# | /usr/include/x86_64-linux-gnu/bits/mathcalls.h:213:23: note: conflicting declaration
# | 213 | __MATHDECL_ALIAS (int,isnan,, (_Mdouble_ __value), isnan)
# | | ^
# | 2 errors generated.
# `-----------------------------
# error: command failed with exit status: 1
```
https://github.com/llvm/llvm-project/pull/98952
More information about the libcxx-commits
mailing list