From ad4f99101437a6adc0f481a0d8902a78fd64f441 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 22 Oct 2002 23:44:25 +0000 Subject: [PATCH] re PR c++/6579 (Infinite loop with statement expressions in member initialization) PR c++/6579 * spew.c (snarf_parenthesized_expression): New function. (snarf_block): Use it. PR c++/6579 * g++.dg/parse/stmtexpr3.C: New test. From-SVN: r58427 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/spew.c | 27 ++++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/stmtexpr3.C | 8 ++++++++ 4 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/stmtexpr3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6f73ad911d1..2529697ba4a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2002-10-22 Mark Mitchell + + PR c++/6579 + * spew.c (snarf_parenthesized_expression): New function. + (snarf_block): Use it. + 2002-10-22 Richard Henderson * method.c (use_thunk): Always compute vcall_value; assert that diff --git a/gcc/cp/spew.c b/gcc/cp/spew.c index 8633bb8c4c5..1d671252126 100644 --- a/gcc/cp/spew.c +++ b/gcc/cp/spew.c @@ -133,6 +133,7 @@ static struct unparsed_text * alloc_unparsed_text static void snarf_block PARAMS ((struct unparsed_text *t)); static tree snarf_defarg PARAMS ((void)); +static void snarf_parenthesized_expression (struct unparsed_text *); static int frob_id PARAMS ((int, int, tree *)); /* The list of inline functions being held off until we reach the end of @@ -1067,6 +1068,30 @@ alloc_unparsed_text (locus, decl, interface) return r; } +/* Accumulate the tokens that make up a parenthesized expression in T, + having already read the opening parenthesis. */ + +static void +snarf_parenthesized_expression (struct unparsed_text *t) +{ + int yyc; + int level = 1; + + while (1) + { + yyc = next_token (space_for_token (t)); + if (yyc == '(') + ++level; + else if (yyc == ')' && --level == 0) + break; + else if (yyc == 0) + { + error ("%Hend of file read inside definition", &t->locus); + break; + } + } +} + /* Subroutine of snarf_method, deals with actual absorption of the block. */ static void @@ -1145,6 +1170,8 @@ snarf_block (t) else if (look_for_semicolon && blev == 0) break; } + else if (yyc == '(' && blev == 0) + snarf_parenthesized_expression (t); else if (yyc == 0) { error ("%Hend of file read inside definition", &t->locus); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78e741793b3..8635fdc2c81 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-10-22 Mark Mitchell + + PR c++/6579 + * g++.dg/parse/stmtexpr3.C: New test. + 2002-10-22 Nathan Sidwell * g++.dg/expr/cond1.C: New test. diff --git a/gcc/testsuite/g++.dg/parse/stmtexpr3.C b/gcc/testsuite/g++.dg/parse/stmtexpr3.C new file mode 100644 index 00000000000..79f689316ae --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/stmtexpr3.C @@ -0,0 +1,8 @@ +// { dg-do compile } +// { dg-options "" } + +struct B +{ + int a; + B() : a(({ 1; })) {} +}; -- 2.30.2