[libcxx-commits] [libcxx] feat libcxx: avoid defining std::nullptr_t in terms of ::nullptr_t (PR #73442)

Anton Zhilin via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 26 03:14:27 PST 2023


https://github.com/Anton3 created https://github.com/llvm/llvm-project/pull/73442

Before this PR, `<cstddef>` did

```cpp
using nullptr_t = ::nullptr_t;
```

`::nullptr_t` comes from `<stddef.h>` (of libc++), which uses `#include_next` to make the compiler look into glibc's `<stddef.h>` for the definition of `::nullptr_t`.

Such behavior confused some editors, notably CLion Nova, into thinking that `std::nullptr_t` does not exist, which turned off essentially all intellisense features.

The C++ Standard committee decided that `<stddef.h>` exposing `::nullptr_t` is a bug and that `std::nullptr_t` should not rely on `::nullptr_t`: https://timsong-cpp.github.io/lwg-issues/3484

>From 7d93a92eb716b9e10656c56dd3417bfc4a983a45 Mon Sep 17 00:00:00 2001
From: Anton Zhilin <antonyzhilin at gmail.com>
Date: Sun, 26 Nov 2023 14:12:09 +0300
Subject: [PATCH] feat libcxx: avoid defining std::nullptr_t in terms of
 ::nullptr_t

Before this PR, `<cstddef>` did

```cpp
using nullptr_t = ::nullptr_t;
```

`::nullptr_t` comes from `<stddef.h>` (of libc++), which uses `#include_next` to make the compiler look into glibc's `<stddef.h>` for the definition of `::nullptr_t`.

Such behavior confused some editors, notably CLion Nova, into thinking that `std::nullptr_t` does not exist, which turned off essentially all intellisense features.

The C++ Standard committee decided that `<stddef.h>` exposing `::nullptr_t` is a bug and that `std::nullptr_t` should not rely on `::nullptr_t`:
https://timsong-cpp.github.io/lwg-issues/3484
---
 libcxx/include/cstddef | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/cstddef b/libcxx/include/cstddef
index 3844d4a373323db..3bb4d3b18102af7 100644
--- a/libcxx/include/cstddef
+++ b/libcxx/include/cstddef
@@ -56,7 +56,7 @@ Types:
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-using ::nullptr_t;
+using nullptr_t = decltype(nullptr);
 using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS;
 using ::size_t _LIBCPP_USING_IF_EXISTS;
 



More information about the libcxx-commits mailing list