Skip to content

[clang] Add __nullptr as a keyword to C #123119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 27, 2025
Merged

Conversation

AidanGoldfarb
Copy link
Contributor

@AidanGoldfarb AidanGoldfarb commented Jan 15, 2025

This PR resolves #121503.

I was not sure whether I added my test in the correct place, and if so, if that deprecates nullptr-98.cpp

@AidanGoldfarb AidanGoldfarb changed the title Adding __nullptr as a keyword to C [clang] Adding __nullptr as a keyword to C Jan 15, 2025
@AidanGoldfarb AidanGoldfarb changed the title [clang] Adding __nullptr as a keyword to C [clang] Add __nullptr as a keyword to C Jan 15, 2025
@AidanGoldfarb AidanGoldfarb marked this pull request as ready for review January 16, 2025 02:06
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-clang

Author: Aidan Goldfarb (AidanGoldfarb)

Changes

This PR resolves #121503.

I was not sure whether I added my test in the correct place, and if so, if that deprecates nullptr-98.cpp


Full diff: https://github.com/llvm/llvm-project/pull/123119.diff

2 Files Affected:

  • (modified) clang/include/clang/Basic/TokenKinds.def (+1-1)
  • (modified) clang/test/Sema/nullptr.c (+3)
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 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.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

Copy link
Member

@Sirraide Sirraide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall, but this still needs a release note.

@@ -108,3 +108,6 @@ void test_f1() {
int ir = (f1)(nullptr);
}

// __nullptr keyword in C
void foo(void *);
void bar() { foo(__nullptr); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing newline at the end of the file

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be sure to also update clang/docs/ReleaseNotes.rst so users know about the new functionality. Also, not signing you up for this work, but we really should document all of these keywords in clang/docs/LanguageExtensions.rst. Maybe it's worth starting with this one and hopefully we can backfill the rest in the future?

Aidan and others added 8 commits January 27, 2025 12:48
static_assert(nullptr == __nullptr) and static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
Removed duplicate test
@AidanGoldfarb
Copy link
Contributor Author

Updating LanguageExtensions.rst before merge (and final reviews).

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from a change to the documentation. Thank you!

@AidanGoldfarb AidanGoldfarb merged commit 7fd5833 into llvm:main Jan 27, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Clang] __nullptr isn't available in C
5 participants