This code should work for any C11-compliant compiler:
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#define HEDLEY__IS_CONSTEXPR(expr) _Generic((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
int main(void) {
assert(HEDLEY__IS_CONSTEXPR(1729) == 1);
return 0;
}
However, it fails with PGI:
$ pgcc -c11 -oconstant pgi-constant.c
PGC-S-0155-No appropriate _Generic selection expression found (pgi-constant.c: 8)
PGC-S-0000-Internal compiler error. mkexpr: bad id 0 (pgi-constant.c: 8)
PGC-S-0000-Internal compiler error. mkexpr: bad id 0 (pgi-constant.c: 8)
PGC-S-0103-Illegal operand types for comparison operator (pgi-constant.c: 8)
PGC/x86-64 Linux 18.4-0: compilation completed with severe errors
There is more information about why/how this (should) work at c - Detecting Integer Constant Expressions in Macros - Stack Overflow