[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Including config.h emits warnings from -Wundef
From: |
Bruno Haible |
Subject: |
Re: Including config.h emits warnings from -Wundef |
Date: |
Thu, 03 Aug 2023 18:11:29 +0200 |
On Donnerstag, 3. August 2023 17:52:29 CEST Tim Rühsen wrote:
> Hi,
>
> I just updated gnulib and recognized these warnings with every '#include
> <config.h>'. Before the update there were no warnings.
>
> ../config.h:3317:34: warning: "__cplusplus" is not defined, evaluates to
> 0 [-Wundef]
> 3317 | #if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 &&
> !defined alignof
> | ^~~~~~~~~~~
> ../config.h:3318:6: warning: "HAVE_STDALIGN_H" is not defined, evaluates
> to 0 [-Wundef]
> 3318 | # if HAVE_STDALIGN_H
> | ^~~~~~~~~~~~~~~
> ../config.h:3415:7: warning: "HAVE_STDALIGN_H" is not defined, evaluates
> to 0 [-Wundef]
> 3415 | # if !HAVE_STDALIGN_H
> | ^~~~~~~~~~~~~~~
> ../config.h:3424:6: warning: "_GL_STDALIGN_NEEDS_STDDEF" is not defined,
> evaluates to 0 [-Wundef]
> 3424 | # if _GL_STDALIGN_NEEDS_STDDEF
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
>
> Disabling -Wundef for the whole project is not my preferred solution =).
> Using a #pragma around the #include is ugly and tedious (too many files
> to change).
Using a #pragma include config.h would also be ugly.
> Can this be fixed in gnulib ?
Done:
2023-08-03 Bruno Haible <bruno@clisp.org>
alignasof, stdalign: Avoid some -Wundef warnings from config.h.
Reported by Tim Rühsen <tim.ruehsen@gmx.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-08/msg00012.html>.
* m4/stdalign.m4 (gl_ALIGNASOF): Test whether __cplusplus is defined
before evaluating it. Assume HAVE_STDALIGN_H, _GL_STDALIGN_NEEDS_STDDEF
are never defined to 0.
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index 1a236d66d2..6a39ffe756 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -68,8 +68,10 @@ AC_DEFUN([gl_ALIGNASOF]
dnl The "zz" puts this toward config.h's end, to avoid potential
dnl collisions with other definitions.
AH_VERBATIM([zzalignas],
-[#if !defined HAVE_C_ALIGNASOF && __cplusplus < 201103 && !defined alignof
-# if HAVE_STDALIGN_H
+[#if !defined HAVE_C_ALIGNASOF \
+ && !(defined __cplusplus && 201103 <= __cplusplus) \
+ && !defined alignof
+# if defined HAVE_STDALIGN_H
# include <stdalign.h>
# endif
@@ -166,7 +168,7 @@ AC_DEFUN([gl_ALIGNASOF]
# define _Alignas(a) __declspec (align (a))
# endif
# endif
-# if !HAVE_STDALIGN_H
+# if !defined HAVE_STDALIGN_H
# if ((defined _Alignas \
&& !(defined __cplusplus \
&& (201103 <= __cplusplus || defined _MSC_VER))) \
@@ -175,7 +177,7 @@ AC_DEFUN([gl_ALIGNASOF]
# endif
# endif
-# if _GL_STDALIGN_NEEDS_STDDEF
+# if defined _GL_STDALIGN_NEEDS_STDDEF
# include <stddef.h>
# endif
#endif])