[Bug 255290] _POSIX_C_SOURCE=200809 hides static_assert

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Wed Apr 21 06:22:38 UTC 2021


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255290

            Bug ID: 255290
           Summary: _POSIX_C_SOURCE=200809 hides static_assert
           Product: Base System
           Version: Unspecified
          Hardware: Any
               URL: https://github.com/gbdev/rgbds/issues/789
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: standards
          Assignee: standards at FreeBSD.org
          Reporter: tobik at freebsd.org

$ cat test.c <<EOF
#include <assert.h>
int main() { static_assert(1 == 1, ""); }
EOF
$ cc -D_POSIX_C_SOURCE=200809L -std=gnu11 test.c
test.c:2:14: warning: implicit declaration of function 'static_assert' is
invalid in C99 [-Wimplicit-function-declaration]
int main() { static_assert(1 == 1, ""); }
             ^
1 warning generated.
ld: error: undefined symbol: static_assert
>>> referenced by test.c
>>>               /tmp/test-8e234d.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)

This affects devel/rgbds where I had to remove _POSIX_C_SOURCE.

In assert.h we have:
#if __ISO_C_VISIBLE >= 2011 && !defined(__cplusplus)
#define static_assert   _Static_assert
#endif

In sys/cdefs.h we have:
#if _POSIX_C_SOURCE >= 200809
#define __POSIX_VISIBLE         200809
#define __ISO_C_VISIBLE         1999

so static_assert is hidden when _POSIX_C_SOURCE=200809L because
__ISO_C_VISIBLE is clamped to 1999.  I've reported this upstream
but we have found no evidence that POSIX 2008 mandates C99 and
should hide static_assert.

On Linux with musl and glibc and OpenBSD this works fine.

OpenBSD uses __STDC_VERSION__ instead of __ISO_C_VISIBLE
in assert.h which might be the more correct choice.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-standards mailing list