[clang] [clang] Add __nullptr as a keyword to C (PR #123119)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 09:29:36 PST 2025
================
@@ -108,3 +108,8 @@ void test_f1() {
int ir = (f1)(nullptr);
}
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
----------------
AaronBallman wrote:
Given that this is intended to expose `nullptr` in language modes which don't have it, I think we may also want some test coverage for C17 along the lines of:
```
void foo(struct S *);
void bar() { foo(__nullptr); } // Test that it converts properly to an arbitrary pointer type without warning
_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
_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.
```
https://github.com/llvm/llvm-project/pull/123119
More information about the cfe-commits
mailing list