Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH] configure: Explicitly check for static_assert
Date: Thu, 21 Mar 2024 16:41:44 +0100
Message-ID: <DU0P250MB074747A7EF71A16009ACCF488F322@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM> (raw)

C11 provides static assertions via _Static_assert and
provides static_assert as a convenience define for this
in assert.h. MSVC 19.27 declares support C11, but does
not support _Static_assert, but somehow supports
static_assert. That's therefore what we use.

But apparently there are some old GCC toolchains where
_Static_assert is supported, but assert.h does not provide
the fallback define. Some fate boxes are affected by this
[1].

This commit therefore checks whether static_assert works
with assert.h included; if not, it checks whether using
-Dstatic_assert=_Static_assert fixes it. Otherwise it errors
out.

[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 | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/configure b/configure
index 6d7b33b0ff..61075608ea 100755
--- a/configure
+++ b/configure
@@ -5589,6 +5589,21 @@ 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"; }
 
+for static_assert in "" _Static_assert; do
+    test_cc ${static_assert:+-Dstatic_assert=$static_assert} <<EOF && { test -z "$static_assert" || add_cppflags "-Dstatic_assert=$static_assert"; } && break
+#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
+done || die "Compiler lacks support for C11 static_assert"
+
 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".

                 reply	other threads:[~2024-03-21 15:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DU0P250MB074747A7EF71A16009ACCF488F322@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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