]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/23333 (accepts invalid pure specifier)
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Thu, 22 Dec 2005 12:01:44 +0000 (12:01 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Thu, 22 Dec 2005 12:01:44 +0000 (12:01 +0000)
2005-12-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

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

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

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

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

From-SVN: r108947

gcc/ChangeLog
gcc/c-lex.c
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error25.C
libcpp/ChangeLog
libcpp/include/cpplib.h

index b1b50aa7398f3c2d764222120b214b5ae7e49305..abed9bd23ef50c5e1cd51564b98885a8223cee93 100644 (file)
@@ -1,3 +1,9 @@
+2005-12-22  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'.
+
 2005-12-22  Kazu Hirata  <kazu@codesourcery.com>
 
        PR tree-optimization/23518
index e745388bc59e9b69ed86bb15ece4275decdf0b68..af3695f6e5a88084238eba3bea0d8fd30a8fb421 100644 (file)
@@ -333,6 +333,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
   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 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
            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 +477,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
     }
 
   if (cpp_flags)
-    *cpp_flags = tok->flags;
+    *cpp_flags = tok->flags | add_flags;
 
   if (!no_more_pch)
     {
index 766fbd527638aa4cb09af25415b9e532aa9f8240..361202edb41b02125a54ccf96221b5e814b8c3da 100644 (file)
@@ -1,3 +1,9 @@
+2005-12-22  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'.
+
 2005-12-20  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/21228
index 3079faa6b9429234f5998d4d4f69911703f8a70a..ca561768ff09134491a1f6530c6e6c0dac8ef465 100644 (file)
@@ -13648,18 +13648,13 @@ cp_parser_pure_specifier (cp_parser* parser)
     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.
index 4734f8150bdeaff676e709283b6dd5225a3d7e1c..089e08802be4bf9df8b8794547114b34cb40bc96 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/23333
+       * g++.dg/parse/error25.C: Add more tests.
+
 2005-12-22  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/18990
index a726a174bb426f017ccb07345ec5fd43cf7bbd58..360b40f2e7effd8925e71e134c00aa2e1c4df694 100644 (file)
@@ -11,6 +11,7 @@ class foo
   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 d96b55f07a6d116e29fa7f9147de00a19832ecd4..e21ea6dc524766f95b858992c85f72cf63a4f3d0 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/23333
+       * include/cpplib.h: Add PURE_ZERO to flags for the cpp_token structure.
+
 2005-12-07  Jon Grimm  <jgrimm2@us.ibm.com>
            Ben Elliston  <bje@au.ibm.com>
 
index b5bece5e5d60bc9789de3b2222e5c1c777868a3b..0ab66357341b47860748571f0c5029be3d91932c 100644 (file)
@@ -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.  */