This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to support "const const" for C99
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 10 Nov 2002 16:26:26 +0000 (GMT)
- Subject: Patch to support "const const" for C99
Though in the cases of duplicate type qualifiers recently discussed on
the gcc list GCC acts standards-correctly (albeit with a question of
whether the pedwarns should be only if pedantic), it doesn't properly
implement the "const const" case where the duplicate qualifiers are
given explicitly in the same list, which is also allowed by C99. This
patch fixes this (a mainline regression of sorts, since 3.2 -std=gnu99
would just give a (wrong) pedwarn but mainline gives a hard error as a
result of my patch which to make cases such as "short short" into hard
errors).
(If the other duplicate qualifiers pedwarns are restricted to when
pedantic, this one should be as well.)
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline.
2002-11-10 Joseph S. Myers <jsm@polyomino.org.uk>
* c-decl.c (grokdeclarator): Make error for duplicate type
qualifiers into a pedwarn, disabled for C99.
testsuite:
2002-11-10 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/c90-idem-qual-2.c, gcc.dg/c99-idem-qual-2.c: New tests.
--- c-decl.c.orig 2002-11-06 22:48:01.000000000 +0000
+++ c-decl.c 2002-11-10 01:25:05.000000000 +0000
@@ -3541,7 +3541,15 @@ grokdeclarator (declarator, declspecs, d
}
}
else if (specbits & (1 << (int) i))
- error ("duplicate `%s'", IDENTIFIER_POINTER (id));
+ {
+ if (i == RID_CONST || i == RID_VOLATILE || i == RID_RESTRICT)
+ {
+ if (!flag_isoc99)
+ pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
+ }
+ else
+ error ("duplicate `%s'", IDENTIFIER_POINTER (id));
+ }
/* Diagnose "__thread extern". Recall that this list
is in the reverse order seen in the text. */
--- testsuite/gcc.dg/c90-idem-qual-2.c 2002-08-26 16:21:36.000000000 +0000
+++ testsuite/gcc.dg/c90-idem-qual-2.c 2002-11-10 01:25:37.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test for idempotent type qualifiers: in C99 only. Test "const const". */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+const const int foo; /* { dg-bogus "warning" "warning in place of error" } */
+/* { dg-error "duplicate" "duplicate type qualifier error" { target *-*-* } 6 } */
--- testsuite/gcc.dg/c99-idem-qual-2.c 2002-08-26 16:21:36.000000000 +0000
+++ testsuite/gcc.dg/c99-idem-qual-2.c 2002-11-10 01:25:44.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test for idempotent type qualifiers: in C99 only. Test "const const". */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+const const int foo; /* { dg-bogus "duplicate" "duplicate type qualifier error" } */
--
Joseph S. Myers
jsm28@cam.ac.uk