This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Trivial _Imaginary keyword support (no imaginary types)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 3 May 2009 14:08:22 +0000 (UTC)
- Subject: Trivial _Imaginary keyword support (no imaginary types)
This patch makes GCC understand the _Imaginary keyword to the minimum
extent required by the normative parts of C99: as a reserved keyword
that cannot be used as an identifier but cannot appear anywhere in a
valid program either so must yield a syntax error whenever used. As I
noted in <http://gcc.gnu.org/ml/gcc/2005-08/msg00527.html>, this is
not particularly useful, but it appears to be correct according to
C99. (C99 TC3 does allow <complex.h> to follow Annex G regarding
imaginary types but makes no other changes to the normative standard
regarding them.)
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied
to mainline.
2009-05-03 Joseph Myers <joseph@codesourcery.com>
* c-common.c (reswords): Add _Imaginary.
* c-common.c (enum rid): Add RID_IMAGINARY.
testsuite:
2009-05-03 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/c99-complex-3.c: New test.
Index: testsuite/gcc.dg/c99-complex-3.c
===================================================================
--- testsuite/gcc.dg/c99-complex-3.c (revision 0)
+++ testsuite/gcc.dg/c99-complex-3.c (revision 0)
@@ -0,0 +1,7 @@
+/* Test for _Imaginary: when imaginary types are not implemented, this
+ is still a keyword and must give a syntax error if used rather than
+ being treated as an identifier. */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+float _Imaginary; /* { dg-error "expected" } */
Index: c-common.c
===================================================================
--- c-common.c (revision 147065)
+++ c-common.c (working copy)
@@ -730,6 +730,7 @@
{
{ "_Bool", RID_BOOL, D_CONLY },
{ "_Complex", RID_COMPLEX, 0 },
+ { "_Imaginary", RID_IMAGINARY, D_CONLY },
{ "_Decimal32", RID_DFLOAT32, D_CONLY | D_EXT },
{ "_Decimal64", RID_DFLOAT64, D_CONLY | D_EXT },
{ "_Decimal128", RID_DFLOAT128, D_CONLY | D_EXT },
Index: c-common.h
===================================================================
--- c-common.h (revision 147065)
+++ c-common.h (working copy)
@@ -63,6 +63,10 @@
/* ObjC */
RID_IN, RID_OUT, RID_INOUT, RID_BYCOPY, RID_BYREF, RID_ONEWAY,
+ /* C (reserved and imaginary types not implemented, so any use is a
+ syntax error) */
+ RID_IMAGINARY,
+
/* C */
RID_INT, RID_CHAR, RID_FLOAT, RID_DOUBLE, RID_VOID,
RID_ENUM, RID_STRUCT, RID_UNION, RID_IF, RID_ELSE,
--
Joseph S. Myers
joseph@codesourcery.com