This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Reject invalid specifiers for virtual functions


On 12 Dec, Mark Mitchell wrote:
> Volker Reichelt wrote:
> 
>> The following patch adds NAMED_OP to the cpp_flags in c_lex_with_flags
>> when a single '0' is encountered.
>> In cp_parser_pure_specifier we then check for NAMED_OP to identify a
>> correct pure specifier.
> 
>> Bootstrapped and regtested on x86_64-unknown-linux-gnu.
>> Ok for mainline?
> 
> I'm very excited about eliminating this long-standing wart, but I'm not
> happy about the overload of NAMED_OP.  I think it would be cleaner to
> create an extra flag in cpplib.h.  It looks like we've got one more bit
> and I think we should use it.

How about the following patch then?
It uses a new flag PURE_ZERO instead of 'borrowing' NAMED_OP.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?

Regards,
Volker


2005-12-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23333
	* include/cpplib.h: Add PURE_ZERO to flags for the cpp_token structure.

======================================================================
--- gcc/libcpp/include/cpplib.h	2005-12-13 21:46:52 +0100
+++ gcc/libcpp/include/cpplib.h	2005-12-13 21:52:09 +0100
@@ -172,6 +172,8 @@ struct cpp_string GTY(())
 #define NAMED_OP	(1 << 4) /* C++ named operators.  */
 #define NO_EXPAND	(1 << 5) /* Do not macro-expand this token.  */
 #define BOL		(1 << 6) /* Token at beginning of line.  */
+#define PURE_ZERO	(1 << 7) /* Single 0 digit, used by the C++ frontend,
+				    set in c-lex.c.  */
 
 /* Specify which field, if any, of the cpp_token union is used.  */
 
======================================================================

2005-12-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23333
	* c-lex.c (c_lex_with_flags): Add PURE_ZERO to cpp_flags if
	number is a single digit '0'.

======================================================================
--- gcc/gcc/c-lex.c	2004-10-27 19:24:20 +0200
+++ gcc/gcc/c-lex.c	2005-12-08 22:04:04 +0100
@@ -333,6 +333,7 @@ c_lex_with_flags (tree *value, unsigned 
   static bool no_more_pch;
   const cpp_token *tok;
   enum cpp_ttype type;
+  unsigned char add_flags = 0;
 
   timevar_push (TV_CPP);
  retry:
@@ -366,6 +367,10 @@
 	    break;
 
 	  case CPP_N_INTEGER:
+	    /* C++ uses '0' to mark virtual functions as pure.
+	       Set PURE_ZERO to pass this information to the C++ parser.  */
+	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
+	      add_flags = PURE_ZERO;
 	    *value = interpret_integer (tok, flags);
 	    break;
 
@@ -472,7 +476,7 @@ c_lex_with_flags (tree *value, unsigned 
     }
 
   if (cpp_flags)
-    *cpp_flags = tok->flags;
+    *cpp_flags = tok->flags | add_flags;
 
   if (!no_more_pch)
     {
======================================================================

2005-12-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23333
	* parser.c (cp_parser_pure_specifier): Check for PURE_ZERO to
	identify a single '0'.

======================================================================
--- gcc/gcc/cp/parser.c	2005-09-16 20:35:31 +0200
+++ gcc/gcc/cp/parser.c	2005-12-08 22:04:24 +0100
@@ -13639,18 +13639,13 @@ cp_parser_pure_specifier (cp_parser* par
     return error_mark_node;
   /* Look for the `0' token.  */
   token = cp_lexer_consume_token (parser->lexer);
-  if (token->type != CPP_NUMBER || !integer_zerop (token->value))
-    {
-      cp_parser_error (parser,
-		       "invalid pure specifier (only `= 0' is allowed)");
-      cp_parser_skip_to_end_of_statement (parser);
-      return error_mark_node;
-    }
+  /* c_lex_with_flags marks a single digit '0' with PURE_ZERO.  */
+  if (token->type == CPP_NUMBER && (token->flags & PURE_ZERO))
+    return integer_zero_node;
 
-  /* FIXME: Unfortunately, this will accept `0L' and `0x00' as well.
-     We need to get information from the lexer about how the number
-     was spelled in order to fix this problem.  */
-  return integer_zero_node;
+  cp_parser_error (parser, "invalid pure specifier (only `= 0' is allowed)");
+  cp_parser_skip_to_end_of_statement (parser);
+  return error_mark_node;
 }
 
 /* Parse a constant-initializer.
======================================================================

2005-12-13  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23333
	* g++.dg/parse/error25.C: Add more tests.

===================================================================
--- gcc/gcc/testsuite/g++.dg/parse/error25.C	(revision 108272)
+++ gcc/gcc/testsuite/g++.dg/parse/error25.C	(working copy)
@@ -11,6 +11,7 @@
   virtual void bar2 () = __null;  // { dg-error "invalid pure specifier" }
   virtual void bar3 () = 4;       // { dg-error "invalid pure specifier" }
   virtual void bar4 () = A::f;    // { dg-error "invalid pure specifier" }
+  virtual void bar5 () = 0l;      // { dg-error "invalid pure specifier" }
+  virtual void bar6 () = 00;      // { dg-error "invalid pure specifier" }
+  virtual void bar7 () = 0x0;     // { dg-error "invalid pure specifier" }
 };
-
-
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]