[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fix AC_C_CONST to work with CFLAGS -O2 -Wall -Werror
From: |
Didier Barvaux |
Subject: |
fix AC_C_CONST to work with CFLAGS -O2 -Wall -Werror |
Date: |
Sat, 10 May 2008 17:37:25 +0200 |
Hi all,
I seems that GCC fails to compile the code generated by the AC_C_CONST
macro if the -O2 -Wall -Werror CFLAGS are specified.
I tried with both autoconf 2.61 and 2.62.17-684d2-dirty (taken from git
repo). GCC version is 4.1.2.
Below is the part of the config.log file describing what appends:
configure:25803: checking for an ANSI C-conforming const
configure:25878: gcc -c -g -O2 -Wno-unused-function -Wall -Werror conftest.c >&5
cc1: warnings being treated as errors
conftest.c: In function 'main':
conftest.c:76: warning: 't' is used uninitialized in this function
conftest.c:92: warning: 'b' is used uninitialized in this function
conftest.c:98: warning: 'cs[0]' is used uninitialized in this function
configure:25885: $? = 1
configure: failed program was:
[...]
| int
| main ()
| {
| /* FIXME: Include the comments suggested by Paul. */
| #ifndef __cplusplus
| /* Ultrix mips cc rejects this. */
| typedef int charset[2];
| const charset cs;
| /* SunOS 4.1.1 cc rejects this. */
| char const *const *pcpcc;
| char **ppc;
| /* NEC SVR4.0.2 mips cc rejects this. */
| struct point {int x, y;};
| static struct point const zero = {0,0};
| /* AIX XL C 1.02.0.0 rejects this.
| It does not let you subtract one const X* pointer from another in
| an arm of an if-expression whose if-part is not a constant
| expression */
| const char *g = "string";
| pcpcc = &g + (g ? g-g : 0);
| /* HPUX 7.0 cc rejects these. */
| ++pcpcc;
| ppc = (char**) pcpcc;
| pcpcc = (char const *const *) ppc;
| { /* SCO 3.2v4 cc rejects this. */
| char *t;
| char const *s = 0 ? (char *) 0 : (char const *) 0;
|
| *t++ = 0;
| if (s) return 0;
| }
| { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
| int x[] = {25, 17};
| const int *foo = &x[0];
| ++foo;
| }
| { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
| typedef const int *iptr;
| iptr p = 0;
| ++p;
| }
| { /* AIX XL C 1.02.0.0 rejects this saying
| "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
| struct s { int j; const int *ap[3]; };
| struct s *b; b->j = 5;
| }
| { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
| const int foo = 10;
| if (!foo) return 0;
| }
| return !cs[0] && !zero.x;
| #endif
|
| ;
| return 0;
| }
configure:25900: result: no
Below is a patch that corrects the problem with AC_C_CONST. This patch
works great on my system. It may perhaps break the macro on other
systems, I don't know.
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index ffaa06e..75b0745 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1587,7 +1587,7 @@ AC_DEFUN([AC_C_CONST],
#ifndef __cplusplus
/* Ultrix mips cc rejects this. */
typedef int charset[2];
- const charset cs;
+ const charset cs = { 0, 0 };
/* SunOS 4.1.1 cc rejects this. */
char const *const *pcpcc;
char **ppc;
@@ -1605,10 +1605,7 @@ AC_DEFUN([AC_C_CONST],
ppc = (char**) pcpcc;
pcpcc = (char const *const *) ppc;
{ /* SCO 3.2v4 cc rejects this. */
- char *t;
char const *s = 0 ? (char *) 0 : (char const *) 0;
-
- *t++ = 0;
if (s) return 0;
}
{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
@@ -1624,7 +1621,9 @@ AC_DEFUN([AC_C_CONST],
{ /* AIX XL C 1.02.0.0 rejects this saying
"k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
struct s { int j; const int *ap[3]; };
- struct s *b; b->j = 5;
+ struct s a;
+ struct s *b = &a;
+ b->j = 5;
}
{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
const int foo = 10;
Any comments are welcome.
Didier Barvaux
signature.asc
Description: PGP signature
- fix AC_C_CONST to work with CFLAGS -O2 -Wall -Werror,
Didier Barvaux <=