Open Quuxplusone opened 5 years ago
Bugzilla Link | PR38216 |
Status | NEW |
Importance | P enhancement |
Reported by | Hao Zhong (zhonghao@pku.org.cn) |
Reported on | 2018-07-18 17:54:50 -0700 |
Last modified on | 2020-09-29 13:02:37 -0700 |
Version | unspecified |
Hardware | PC Linux |
CC | dgregor@apple.com, llvm-bugs@lists.llvm.org, mclow.lists@gmail.com, richard-llvm@metafoo.co.uk, zilla@kayari.org |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Clang++ accepts when using libc++.
The problem is that we added this in libc++, whereas GCC added it in their compiler-specific stddef.h wrapper.
Question is, who should change? Should libstdc++ change, in that it's not providing a correct C++ standard library implementation when used with a C standard library
(We already make the latter choice on Windows platforms, where the native
IMHO nullptr_t should only have been required by
Libstdc++ could provide its own
We do that for
A simpler libstdc++ change would be to just add it to the global namespace
unconditionally in <bits/c++config.h>, which is where we add it to namespace
std, not in <cstddef>.
I think that would be conforming, since any std::lib header is allowed to
include <cstddef> and it's unspecified whether that adds its names to just
namespace std or also the global namespace.
I don't much like that, but would be less unhappy if it was conditional:
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -251,6 +251,12 @@ namespace std
#endif
}
+#if __clang__
+// GCC's <stddef.h> defines ::nullptr_t but Clang uses a different <stddef.h>
+// that might not define it. Ensure it's present in the global namespace:
+using std::nullptr_t;
+#endif
+
#define _GLIBCXX_USE_DUAL_ABI
#if ! _GLIBCXX_USE_DUAL_ABI
ICC has the same problem, but that's not your concern.
(In reply to Jonathan Wakely from comment #2)
> We do that for <math.h> and <stdlib.h> and it causes problems too often
> (when somebody does -I /usr/include the include order changes and
> #include_next no longer works).
libc++ does this for 18 of the C headers; doing so seemed necessary to get the
right results for the headers where C and C++ have somewhat different
requirements (for instance, we are required to #undef macros that the C headers
"helpfully" define that shadow libc functions). We don't consider ourselves
responsible for problems caused by people misconfiguring their own include
paths.
(In reply to Jonathan Wakely from comment #2)
> IMHO nullptr_t should only have been required by <cstddef> and not
> <stddef.h>. That's what we did for std::byte. Too late now though.
Maybe it's not too late, there seems to be support for removing it.
https://wg21.link/lwg3484
(In reply to Jonathan Wakely from comment #6)
> (In reply to Jonathan Wakely from comment #2)
> > IMHO nullptr_t should only have been required by <cstddef> and not
> > <stddef.h>. That's what we did for std::byte. Too late now though.
>
> Maybe it's not too late, there seems to be support for removing it.
> https://wg21.link/lwg3484
There's usually support for removing things from people who won't get the bug
reports when code using it breaks ;-)
That being said, we have implementation divergence, and we should resolve that.