diff mbox series

[FFmpeg-devel,v3] configure: Explicitly check for static_assert, _Static_assert

Message ID GV1P250MB073720AB24FC4F56F3EFAC2D8F312@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 0d43adcbef9a061c95db60eb351937c27e2a0609
Headers show
Series [FFmpeg-devel,v3] configure: Explicitly check for static_assert, _Static_assert | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt March 22, 2024, 9:52 p.m. UTC
C11 provides static assertions via _Static_assert and
provides static_assert as a convenience define for this
in assert.h. Our codebase uses the latter, as _Static_assert
has actually already been deprecated in C23.

Not all toolchains that declare support for C11 actually
support it; e.g. MSVC 19.27 does not support _Static_assert,
but somehow supports static_assert. MSVC 19.27 admits to be
a "preview implementation of the ISO C11 standard",
so this is not surprising (MSVC 19.28 does not come with
this caveat).

Furthermore some FATE boxes [1] use old GCC toolchains (with
only experimental support for C11) where _Static_assert is
supported, but assert.h does not provide the fallback define.
They are broken since the first usage of static_assert.

This commit therefore checks whether static_assert and
_Static_assert work with assert.h included; if not,
configure errors out.

This intentionally drops support for MSVC 19.27. Users like
the old FATE boxes above can still add -Dstatic_assert=_Static_assert
to cflags as a workaround if desired.

[1]: https://fate.ffmpeg.org/report.cgi?time=20240321123620&slot=sh4-debian-qemu-gcc-4.7

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 configure | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Andreas Rheinhardt March 23, 2024, 11:20 a.m. UTC | #1
Andreas Rheinhardt:
> C11 provides static assertions via _Static_assert and
> provides static_assert as a convenience define for this
> in assert.h. Our codebase uses the latter, as _Static_assert
> has actually already been deprecated in C23.
> 
> Not all toolchains that declare support for C11 actually
> support it; e.g. MSVC 19.27 does not support _Static_assert,
> but somehow supports static_assert. MSVC 19.27 admits to be
> a "preview implementation of the ISO C11 standard",
> so this is not surprising (MSVC 19.28 does not come with
> this caveat).
> 
> Furthermore some FATE boxes [1] use old GCC toolchains (with
> only experimental support for C11) where _Static_assert is
> supported, but assert.h does not provide the fallback define.
> They are broken since the first usage of static_assert.
> 
> This commit therefore checks whether static_assert and
> _Static_assert work with assert.h included; if not,
> configure errors out.
> 
> This intentionally drops support for MSVC 19.27. Users like
> the old FATE boxes above can still add -Dstatic_assert=_Static_assert
> to cflags as a workaround if desired.
> 
> [1]: https://fate.ffmpeg.org/report.cgi?time=20240321123620&slot=sh4-debian-qemu-gcc-4.7
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  configure | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/configure b/configure
> index 343edb38ab..fc366549bc 100755
> --- a/configure
> +++ b/configure
> @@ -5589,6 +5589,19 @@ check_cxxflags_cc -std=$stdcxx ctype.h "__cplusplus >= 201103L" ||
>  check_cflags_cc -std=$stdc ctype.h "__STDC_VERSION__ >= 201112L" ||
>      { check_cflags_cc -std=c11 ctype.h "__STDC_VERSION__ >= 201112L" && stdc="c11" || die "Compiler lacks C11 support"; }
>  
> +test_cc <<EOF || die "Compiler lacks support for C11 static assertions"
> +#include <assert.h>
> +#include <stddef.h>
> +struct Foo {
> +    int a;
> +    void *ptr;
> +} obj;
> +static_assert(offsetof(struct Foo, a) == 0,
> +              "First element of struct does not have offset 0");
> +_Static_assert(offsetof(struct Foo, ptr) >= offsetof(struct Foo, a) + sizeof(obj.a),
> +               "elements not properly ordered in struct");
> +EOF
> +
>  check_cppflags -D_FILE_OFFSET_BITS=64
>  check_cppflags -D_LARGEFILE_SOURCE
>  

Will apply this patch tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/configure b/configure
index 343edb38ab..fc366549bc 100755
--- a/configure
+++ b/configure
@@ -5589,6 +5589,19 @@  check_cxxflags_cc -std=$stdcxx ctype.h "__cplusplus >= 201103L" ||
 check_cflags_cc -std=$stdc ctype.h "__STDC_VERSION__ >= 201112L" ||
     { check_cflags_cc -std=c11 ctype.h "__STDC_VERSION__ >= 201112L" && stdc="c11" || die "Compiler lacks C11 support"; }
 
+test_cc <<EOF || die "Compiler lacks support for C11 static assertions"
+#include <assert.h>
+#include <stddef.h>
+struct Foo {
+    int a;
+    void *ptr;
+} obj;
+static_assert(offsetof(struct Foo, a) == 0,
+              "First element of struct does not have offset 0");
+_Static_assert(offsetof(struct Foo, ptr) >= offsetof(struct Foo, a) + sizeof(obj.a),
+               "elements not properly ordered in struct");
+EOF
+
 check_cppflags -D_FILE_OFFSET_BITS=64
 check_cppflags -D_LARGEFILE_SOURCE