I have this very simple program:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
static constexpr const char *const str = "hello";
}
which fails to compile with this error:
$ gcc -std=c2x str.c
str.c: In function 'main':
str.c:6:46: error: 'constexpr' pointer initializer is not null
6 | static constexpr const char *const str = "hello";
| ^~~~~~~
$ gcc -v
...
gcc version 13.1.0 (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders)
Why is nullptr
the only pointer type allowed to be constexpr
?