* [FFmpeg-devel] [PATCH v3] configure: Explicitly check for static_assert, _Static_assert
@ 2024-03-22 21:52 Andreas Rheinhardt
2024-03-23 11:20 ` Andreas Rheinhardt
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2024-03-22 21:52 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: 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
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3] configure: Explicitly check for static_assert, _Static_assert
2024-03-22 21:52 [FFmpeg-devel] [PATCH v3] configure: Explicitly check for static_assert, _Static_assert Andreas Rheinhardt
@ 2024-03-23 11:20 ` Andreas Rheinhardt
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rheinhardt @ 2024-03-23 11:20 UTC (permalink / raw)
To: ffmpeg-devel
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
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-23 11:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 21:52 [FFmpeg-devel] [PATCH v3] configure: Explicitly check for static_assert, _Static_assert Andreas Rheinhardt
2024-03-23 11:20 ` Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git