diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index c42b88015e269..53c5955441ed6 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -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__ -------------------- diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 031c5d84e49f9..d017fadbab05b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -388,6 +388,7 @@ C Language Changes - Extend clang's ```` 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 ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def index 2c692c999bdff..8902a20b07ffa 100644 --- a/clang/include/clang/Basic/TokenKinds.def +++ b/clang/include/clang/Basic/TokenKinds.def @@ -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) diff --git a/clang/test/Sema/nullptr-prec2x.c b/clang/test/Sema/nullptr-prec2x.c index 39479d4343a56..c516c448ca1ab 100644 --- a/clang/test/Sema/nullptr-prec2x.c +++ b/clang/test/Sema/nullptr-prec2x.c @@ -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. diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c index d11765a9c881a..b8c371a418e3e 100644 --- a/clang/test/Sema/nullptr.c +++ b/clang/test/Sema/nullptr.c @@ -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.