C++ preprocessor bug or not ?

Neil Booth neil@daikokuya.demon.co.uk
Tue Feb 6 11:24:00 GMT 2001


Hi John,

As Dave and Philipp pointed out, CPP is correct.  However, the diagnostic
is awful.

This patch address that; it outputs

/tmp/test.c:1:14: operator "defined" requires an identifier
/tmp/test.c:1:14: ("xor" is an alternative token for "^" in C++)

Neil.

	* cppexp.c (parse_defined): Improve diagnostics for invalid
	syntax.

Index: cppexp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppexp.c,v
retrieving revision 1.85
diff -u -p -r1.85 cppexp.c
--- cppexp.c	2001/01/28 01:50:05	1.85
+++ cppexp.c	2001/02/06 19:17:04
@@ -344,7 +344,20 @@ parse_defined (pfile)
 	}
     }
   else
-    cpp_error (pfile, "\"defined\" without an identifier");
+    {
+      cpp_error (pfile, "operator \"defined\" requires an identifier");
+      if (token.flags & NAMED_OP)
+	{
+	  cpp_token op;
+
+	  op.flags = 0;
+	  op.type = token.type;
+	  cpp_error (pfile,
+		     "(\"%s\" is an alternative token for \"%s\" in C++)",
+		     cpp_token_as_text (pfile, &token),
+		     cpp_token_as_text (pfile, &op));
+	}
+    }
 
   if (!node)
     op.op = CPP_ERROR;


More information about the Gcc mailing list