Re: Including config.h emits warnings from -Wundef

2023-08-04 Thread Tim Rühsen

On 8/3/23 20:56, Jeffrey Walton wrote:

My personal opinion is, there's nothing to fix.

That is exactly how macros are supposed to work. Anything undefined
evaluates to 0. It has been that way since the early days of C and
C++.

If there's a fix, then it is that you don't use -Wundef.


-Wundef helps to find typos if #ifdef constructs quickly.

Without it you easily end up debugging issues that the compiler could 
have caught at compile time. This actually happened to me in the past, 
I'd like to take this kind of issue out of the game once and for all :).


Regards, Tim


OpenPGP_signature
Description: OpenPGP digital signature


Re: Including config.h emits warnings from -Wundef

2023-08-03 Thread Bruno Haible
Jeffrey Walton wrote:
> My personal opinion is, there's nothing to fix.
> 
> That is exactly how macros are supposed to work. Anything undefined
> evaluates to 0. It has been that way since the early days of C and
> C++.
> 
> If there's a fix, then it is that you don't use -Wundef.

On the simple level "which gcc warning options do I find useful?", I agree
with you.

But one level higher, there are two more questions

1) "Are different GNU packages entitled to using different gcc warning options?"

Yes, of course. Different developers have made different experiences. If Tim
thinks that the '-Wundef' may possibly, some day, help him detect a mistake,
he's perfectly right in using it.

2) "Which warning options from a GNU package does Gnulib need to support,
when compiling a file from that package?"

Here, the answer is: Any except -Werror.

Note that when compiling a .c file from gnulib, we take the freedom to
deactivate warnings as we like; this is the GL_CFLAG_GNULIB_WARNINGS
mechanism.

Bruno






Re: Including config.h emits warnings from -Wundef

2023-08-03 Thread Jeffrey Walton
On Thu, Aug 3, 2023 at 11:52 AM Tim Rühsen  wrote:
>
> I just updated gnulib and recognized these warnings with every '#include
> '. Before the update there were no warnings.
>
> ../config.h:3317:34: warning: "__cplusplus" is not defined, evaluates to
> 0 [-Wundef]
> [...]
> 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).
>
> Can this be fixed in gnulib ?

My personal opinion is, there's nothing to fix.

That is exactly how macros are supposed to work. Anything undefined
evaluates to 0. It has been that way since the early days of C and
C++.

If there's a fix, then it is that you don't use -Wundef.

Jeff



Re: Including config.h emits warnings from -Wundef

2023-08-03 Thread Tim Rühsen

Awesome, thank you Bruno !

Tested and your patch fixes the issue(s) for me.

Tim

On 8/3/23 18:11, Bruno Haible wrote:

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
'. 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  

alignasof, stdalign: Avoid some -Wundef warnings from config.h.
Reported by Tim Rühsen  in
.
* 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 
  # 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 
  # endif
  #endif])





OpenPGP_signature
Description: OpenPGP digital signature


Re: Including config.h emits warnings from -Wundef

2023-08-03 Thread Bruno Haible
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 
> '. 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  

alignasof, stdalign: Avoid some -Wundef warnings from config.h.
Reported by Tim Rühsen  in
.
* 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 
 # 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 
 # endif
 #endif])






Including config.h emits warnings from -Wundef

2023-08-03 Thread Tim Rühsen

Hi,

I just updated gnulib and recognized these warnings with every '#include 
'. 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).


Can this be fixed in gnulib ?

Regards, Tim


OpenPGP_signature
Description: OpenPGP digital signature