Skip to content
4 changes: 1 addition & 3 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,7 @@ available in all language modes.
__nullptr
---------

``__nullptr`` is an alternate spelling for ``nullptr``, but is also available in
C++ modes prior to C++11. Note that it's currently not availbale in C despite
C23 having support for ``nullptr``.
``__nullptr`` is an alternate spelling for ``nullptr``. It is available in all C and C++ language modes.

__signed, __signed__
--------------------
Expand Down
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ C Language Changes

- Extend clang's ``<limits.h>`` to define ``LONG_LONG_*`` macros for Android's bionic.
- Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and later.
- Exposed the the ``__nullptr`` keyword as an alias for ``nullptr`` in all C language modes.

C2y Feature Support
^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ ALIAS("__decltype" , decltype , KEYCXX)
ALIAS("__imag__" , __imag , KEYALL)
ALIAS("__inline" , inline , KEYALL)
ALIAS("__inline__" , inline , KEYALL)
ALIAS("__nullptr" , nullptr , KEYCXX)
ALIAS("__nullptr" , nullptr , KEYALL)
ALIAS("__real__" , __real , KEYALL)
ALIAS("__restrict" , restrict , KEYALL)
ALIAS("__restrict__" , restrict , KEYALL)
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Sema/nullptr-prec2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ int nullptr; // expected-warning {{'nullptr' is a keyword in C23}}

nullptr_t val; // expected-error {{unknown type name 'nullptr_t'}}

void foo(void *);
void bar() { foo(__nullptr); } // Test that it converts properly to an arbitrary pointer type without warning
_Static_assert(__nullptr == 0, "value of __nullptr"); // Test that its value matches that of NULL
_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 1), "type of __nullptr"); // Test that it's type is not the same as what NULL would generally have.
7 changes: 7 additions & 0 deletions clang/test/Sema/nullptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ void test_f1() {
int ir = (f1)(nullptr);
}

// __nullptr keyword in C
void foo(void *);
void bar() { foo(__nullptr); }
static_assert(nullptr == __nullptr);
static_assert(__nullptr == 0); // Test that its value matches that of NULL
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 1)); // Test that it's type is not the same as what NULL would generally have.
Loading