From 3f115705d3f449dd19ab9a93170d6cd72a50f999 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 4 Apr 2022 14:28:30 +0200 Subject: [PATCH] build: enable `-fms-extensions` This eases incorporating fields from/"subclassing" another struct. Signed-off-by: David Lamparter --- configure.ac | 14 ++++++++++++++ doc/developer/workflow.rst | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/configure.ac b/configure.ac index c636fade7..00cd1efdd 100644 --- a/configure.ac +++ b/configure.ac @@ -330,7 +330,21 @@ LDFLAGS="$LDFLAGS -g" AM_CONDITIONAL([DEV_BUILD], [test "$enable_dev_build" = "yes"]) +dnl -fms-extensions causes clang to have a built-in __wchar_t on OpenBSD, +dnl which just straight up breaks compiling any code. +dnl (2022-04-04 / OpenBSD 7 / clang 11.1.0) +AH_VERBATIM([OpenBSD], [ +#ifdef __OpenBSD__ +#define __wchar_t __wchar_t_ignore +#include +#undef __wchar_t +#endif +]) + dnl always want these CFLAGS +AC_C_FLAG([-fms-extensions], [ + AC_MSG_ERROR([$CC does not support unnamed struct fields (-fms-extensions)]) +]) AC_C_FLAG([-fno-omit-frame-pointer]) AC_C_FLAG([-funwind-tables]) AC_C_FLAG([-Wall]) diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index cbb5c6bf7..adab9725d 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -897,6 +897,26 @@ necessary replacements. | u_long | unsigned long | +-----------+--------------------------+ +FRR also uses unnamed struct fields, enabled with ``-fms-extensions`` (cf. +https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html). The following two +patterns can/should be used where contextually appropriate: + +.. code-block:: c + + struct outer { + struct inner; + }; + +.. code-block:: c + + struct outer { + union { + struct inner; + struct inner inner_name; + }; + }; + + .. _style-exceptions: Exceptions -- 2.39.5