diff mbox

Fix Wundef warnings in posix/confstr.c

Message ID 20140625175953.GS4477@spoyarek.pnq.redhat.com
State New
Headers show

Commit Message

Siddhesh Poyarekar June 25, 2014, 5:59 p.m. UTC
Hi,

The macros in confstr.c are part of the public API and are expected to
be not defined for specific cases.  Hence, it ought to be valid to use
ifdef here instead of trying to massage this into a #if.  My initial
approach was to rearrange the macro test sequence, but I ran into a
gcc/standard bug[1][2], so I opted for the approach with the smallest
diff.

Siddhesh

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36453
[2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_412.htm

	* posix/confstr.c (confstr) [__LP64_OFF64_CFLAGS]: Check if
	_POSIX_V7_LP64_OFF64 is defined.
	[__LP64_OFF64_LDFLAGS]: Likewise.
	* posix/posix-envs.def: Check if macros are defined before
	using them.

Comments

Roland McGrath June 25, 2014, 7:36 p.m. UTC | #1
I was thinking about this and the similar cases in sysconf.c.  I think we
should do something better about them.  The straightforward approach you've
taken is still scarily typo-prone.  At the very least, we can use a macro
that voids actually typing the _POSIX_FOOBAR name type.  Something even
better is more doable for the sysconf case than the confstr one.  But we
should give it some more thought.

Thanks,
Roland
Siddhesh Poyarekar July 10, 2014, 12:03 p.m. UTC | #2
On Wed, Jun 25, 2014 at 12:36:10PM -0700, Roland McGrath wrote:
> I was thinking about this and the similar cases in sysconf.c.  I think we
> should do something better about them.  The straightforward approach you've
> taken is still scarily typo-prone.  At the very least, we can use a macro
> that voids actually typing the _POSIX_FOOBAR name type.  Something even
> better is more doable for the sysconf case than the confstr one.  But we
> should give it some more thought.

I've spent some time on this and I can't see a good way to do this
without making it much more complicated than it needs to be.  We can't
completely avoid typing the _POSIX_* name because we can't use a macro
to check if that name is defined, or at least I cannot see a way to do
it.

All my attempts seem to lead to making a template file that is parsed
to generate a header, which would be overkill and cause way too much
code churn for a slushy freeze.

Siddhesh
diff mbox

Patch

diff --git a/posix/confstr.c b/posix/confstr.c
index a2a1bf2..2a98b4a 100644
--- a/posix/confstr.c
+++ b/posix/confstr.c
@@ -130,7 +130,7 @@  confstr (name, buf, len)
     case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
     case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
 #ifdef __LP64_OFF64_CFLAGS
-# if _POSIX_V7_LP64_OFF64 == -1
+# if defined _POSIX_V7_LP64_OFF64 && _POSIX_V7_LP64_OFF64 == -1
 #  error "__LP64_OFF64_CFLAGS should not be defined"
 # elif !defined _POSIX_V7_LP64_OFF64
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
@@ -175,7 +175,7 @@  confstr (name, buf, len)
     case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
     case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
 #ifdef __LP64_OFF64_LDFLAGS
-# if _POSIX_V7_LP64_OFF64 == -1
+# if defined _POSIX_V7_LP64_OFF64 && _POSIX_V7_LP64_OFF64 == -1
 #  error "__LP64_OFF64_LDFLAGS should not be defined"
 # elif !defined _POSIX_V7_LP64_OFF64
       if (__sysconf (_SC_V7_LP64_OFF64) < 0)
diff --git a/posix/posix-envs.def b/posix/posix-envs.def
index 05043e9..344db28 100644
--- a/posix/posix-envs.def
+++ b/posix/posix-envs.def
@@ -44,7 +44,7 @@ 
 
 START_ENV_GROUP (V7)
 
-#if _POSIX_V7_ILP32_OFF32 > 0
+#if defined _POSIX_V7_ILP32_OFF32 && _POSIX_V7_ILP32_OFF32 > 0
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 #elif defined _POSIX_V7_ILP32_OFF32
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
@@ -52,7 +52,7 @@  KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFF32)
 #endif
 
-#if _POSIX_V7_ILP32_OFFBIG > 0
+#if defined _POSIX_V7_ILP32_OFFBIG && _POSIX_V7_ILP32_OFFBIG > 0
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 #elif defined _POSIX_V7_ILP32_OFFBIG
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
@@ -60,7 +60,7 @@  KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, ILP32_OFFBIG)
 #endif
 
-#if _POSIX_V7_LP64_OFF64 > 0
+#if defined _POSIX_V7_LP64_OFF64 && _POSIX_V7_LP64_OFF64 > 0
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 #elif defined _POSIX_V7_LP64_OFF64
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
@@ -68,7 +68,7 @@  KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 UNKNOWN_ENVIRONMENT (V7, POSIX_V7, LP64_OFF64)
 #endif
 
-#if _POSIX_V7_LPBIG_OFFBIG > 0
+#if defined _POSIX_V7_LPBIG_OFFBIG && _POSIX_V7_LPBIG_OFFBIG > 0
 KNOWN_PRESENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
 #elif defined _POSIX_V7_LPBIG_OFFBIG
 KNOWN_ABSENT_ENVIRONMENT (V7, POSIX_V7, LPBIG_OFFBIG)
@@ -80,7 +80,7 @@  END_ENV_GROUP (V7)
 
 START_ENV_GROUP (V6)
 
-#if _POSIX_V6_ILP32_OFF32 > 0
+#if defined _POSIX_V6_ILP32_OFF32 && _POSIX_V6_ILP32_OFF32 > 0
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 #elif defined _POSIX_V6_ILP32_OFF32
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
@@ -88,7 +88,7 @@  KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFF32)
 #endif
 
-#if _POSIX_V6_ILP32_OFFBIG > 0
+#if defined _POSIX_V6_ILP32_OFFBIG && _POSIX_V6_ILP32_OFFBIG > 0
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 #elif defined _POSIX_V6_ILP32_OFFBIG
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
@@ -96,7 +96,7 @@  KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, ILP32_OFFBIG)
 #endif
 
-#if _POSIX_V6_LP64_OFF64 > 0
+#if defined _POSIX_V6_LP64_OFF64 && _POSIX_V6_LP64_OFF64 > 0
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 #elif defined _POSIX_V6_LP64_OFF64
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
@@ -104,7 +104,7 @@  KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 UNKNOWN_ENVIRONMENT (V6, POSIX_V6, LP64_OFF64)
 #endif
 
-#if _POSIX_V6_LPBIG_OFFBIG > 0
+#if defined _POSIX_V6_LPBIG_OFFBIG && _POSIX_V6_LPBIG_OFFBIG > 0
 KNOWN_PRESENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
 #elif defined _POSIX_V6_LPBIG_OFFBIG
 KNOWN_ABSENT_ENVIRONMENT (V6, POSIX_V6, LPBIG_OFFBIG)
@@ -116,7 +116,7 @@  END_ENV_GROUP (V6)
 
 START_ENV_GROUP (V5)
 
-#if _XBS5_ILP32_OFF32 > 0
+#if defined _XBS5_ILP32_OFF32 && _XBS5_ILP32_OFF32 > 0
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 #elif defined _XBS5_ILP32_OFF32
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
@@ -124,7 +124,7 @@  KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFF32)
 #endif
 
-#if _XBS5_ILP32_OFFBIG > 0
+#if defined _XBS5_ILP32_OFFBIG && _XBS5_ILP32_OFFBIG > 0
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 #elif defined _XBS5_ILP32_OFFBIG
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
@@ -132,7 +132,7 @@  KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, ILP32_OFFBIG)
 #endif
 
-#if _XBS5_LP64_OFF64 > 0
+#if defined _XBS5_LP64_OFF64 && _XBS5_LP64_OFF64 > 0
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 #elif defined _XBS5_LP64_OFF64
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
@@ -140,7 +140,7 @@  KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 UNKNOWN_ENVIRONMENT (XBS5, XBS5, LP64_OFF64)
 #endif
 
-#if _XBS5_LPBIG_OFFBIG > 0
+#if defined _XBS5_LPBIG_OFFBIG && _XBS5_LPBIG_OFFBIG > 0
 KNOWN_PRESENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)
 #elif defined _XBS5_LPBIG_OFFBIG
 KNOWN_ABSENT_ENVIRONMENT (XBS5, XBS5, LPBIG_OFFBIG)