-
Notifications
You must be signed in to change notification settings - Fork 107
Description
E.g a simple c++ program like
#include <cassert>
int main(int argc, const char **argv) {
assert (argc > 0);
return 0;
}
causes
error: '__assert' was not declared in this scope; did you mean 'assert'?
150 | assert(!empty());
| ^~~~~~
Because it gets the pre-c99 macro that expands to __assert because __STDC_VERSION__ is undefined. But the c99 function declaration __assert_c99 because _STDC_C99 is defined.
Commit illumos@b3260c2 split assert.h into two files (assert.h and iso/assert_iso.h) fixing https://www.illumos.org/issues/17491
The assert() macro is defined differently in pre-c99 and c99. Expanding to calls to different functions. So there are preprocessor conditions deciding which macro and which function prototype to use.
The split made the macro end up in assert.h, and the function prototype in assert_iso.h.
The aforementioned commit changed the prototype to use "_STDC_C99" while the macro continued to use __STDC_VERSION__ to check C standard versions.
Normally _STDC_C99 and __STDC_VERSION__ would match and this wouldn't be a problem. As sys/feature_tests.h sets _STD_C99 based on __STDC_VERSION__ value.
However the gcc 13/14 compiler is patched to set _STD_C99 as a predefined macro for C++ code:
TritonDataCenter/pkgsrc-extra@e295cdb
https://github.com/TritonDataCenter/pkgsrc-extra/blob/main/gcc13/patches/patch-gcc_config_sol2.h
https://github.com/TritonDataCenter/pkgsrc-extra/blob/main/gcc14/patches/patch-gcc_config_sol2.h
# C
$ gcc -x c -std=c99 -dM -E - </dev/null | grep 'STDC_[CV]'
#define __STDC_VERSION__ 199901L
# C++
$ gcc -x c++ -std=c++11 -dM -E - </dev/null | grep 'STDC_[CV]'
#define _STDC_C99 1
$ gcc -v 2>&1 | tail -n1
gcc version 13.3.0 (GCC)
I'm not sure if this should go to upstream illumos. But as it is caused by interaction with a downstream patch I'm starting to report it here..