aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPetr Machata <machata@post.cz>2005-12-13 09:01:53 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2005-12-13 09:01:53 +0100
commit6d32822515d3fee23547ea9a680f13e27e877795 (patch)
treebf8b55646f941b7eb59488051cdbb6a754b306e9 /gcc
parent7e825da03edc82020de4d245b22fb123f5e976d8 (diff)
downloadgcc-6d32822515d3fee23547ea9a680f13e27e877795.zip
gcc-6d32822515d3fee23547ea9a680f13e27e877795.tar.gz
gcc-6d32822515d3fee23547ea9a680f13e27e877795.tar.bz2
re PR c++/24907 ("int x, ;" accepted)
2005-12-13 Petr Machata <machata@post.cz> PR c++/24907 * parser.c (cp_parser_simple_declaration): Require comma at the beginning of processing second and later declarators, instead of allowing the comma at the end of each iteration. * g++.dg/parse/comma2.C: New test. From-SVN: r108462
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.c13
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/comma2.C19
4 files changed, 42 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 700b992..e9cfad7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2005-12-13 Petr Machata <machata@post.cz>
+
+ PR c++/24907
+ * parser.c (cp_parser_simple_declaration): Require comma at the
+ beginning of processing second and later declarators, instead of
+ allowing the comma at the end of each iteration.
+
2005-12-12 Mark Mitchell <mark@codesourcery.com>
PR c++/25300
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 8eb4fbf..25488c7 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7145,7 +7145,16 @@ cp_parser_simple_declaration (cp_parser* parser,
bool function_definition_p;
tree decl;
- saw_declarator = true;
+ if (saw_declarator)
+ {
+ /* If we are processing next declarator, coma is expected */
+ token = cp_lexer_peek_token (parser->lexer);
+ gcc_assert (token->type == CPP_COMMA);
+ cp_lexer_consume_token (parser->lexer);
+ }
+ else
+ saw_declarator = true;
+
/* Parse the init-declarator. */
decl = cp_parser_init_declarator (parser, &decl_specifiers,
function_definition_allowed_p,
@@ -7180,7 +7189,7 @@ cp_parser_simple_declaration (cp_parser* parser,
token = cp_lexer_peek_token (parser->lexer);
/* If it's a `,', there are more declarators to come. */
if (token->type == CPP_COMMA)
- cp_lexer_consume_token (parser->lexer);
+ /* will be consumed next time around */;
/* If it's a `;', we are done. */
else if (token->type == CPP_SEMICOLON)
break;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9bde74d..ce14f6a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-13 Petr Machata <machata@post.cz>
+
+ PR c++/24907
+ * g++.dg/parse/comma2.C: New test.
+
2005-12-13 Mark Mitchell <mark@codesourcery.com>
Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/testsuite/g++.dg/parse/comma2.C b/gcc/testsuite/g++.dg/parse/comma2.C
new file mode 100644
index 0000000..0f40587
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/comma2.C
@@ -0,0 +1,19 @@
+// { dg-do compile }
+
+// Copyright (C) 2005 Free Software Foundation, Inc.
+
+// PR c++/24907 [3.4/4.0/4.1/4.2 Regression] "int x, ;" accepted
+
+int x;
+int y,; /* { dg-error "expected" } */
+
+int main()
+{
+ int a;
+ int b,; /* { dg-error "expected" } */
+ int c,d;
+ int e,f,; /* { dg-error "expected" } */
+ int g,h,i;
+ int j,k,l,;/* { dg-error "expected" } */
+ int m,,,n; /* { dg-error "expected" } */
+}