Hi,
On 10/10/2013 08:48 PM, Jason Merrill wrote:
I think that committing was important for two primary reasons:
1. We should not have irreversible side-effects while in a tentative
state. For example, we shouldn't create a permanent entry in the
symbol table, or issue an error message that might not apply if the
tentative parse is aborted. The "tentative" stuff is only in the
parser; there's no easy way to remove a function or variable from
the symbol table, or undo other pieces of global state in the
compiler as a whole.
Right. In cases where there aren't side-effects, this shouldn't be an
issue. We should only use Paolo's new function in such cases; Paolo,
please add that to the comment. The patch is OK with that change.
Thanks. Thus I'm finishing testing the below.
The issue is a regression in 4_7/4_8 too, what should we do in those
branches? I'm thinking applying the change to 4_8 too and either not
fixing in 4_7 or just reverting the cp_parser_commit_to_tentative_parse
change which improved the diagnostic for 47277?
Thanks,
Paolo.
///////////////////////
/cp
2013-10-11 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58633
* parser.c (cp_parser_commit_to_topmost_tentative_parse): New.
(cp_parser_pseudo_destructor_name): Use it.
/testsuite
2013-10-11 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58633
* g++.dg/cpp0x/decltype57.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 203392)
+++ cp/parser.c (working copy)
@@ -2347,6 +2347,8 @@ static void cp_parser_parse_tentatively
(cp_parser *);
static void cp_parser_commit_to_tentative_parse
(cp_parser *);
+static void cp_parser_commit_to_topmost_tentative_parse
+ (cp_parser *);
static void cp_parser_abort_tentative_parse
(cp_parser *);
static bool cp_parser_parse_definitely
@@ -6693,7 +6695,7 @@ cp_parser_pseudo_destructor_name (cp_parser* parse
/* Once we see the ~, this has to be a pseudo-destructor. */
if (!processing_template_decl && !cp_parser_error_occurred (parser))
- cp_parser_commit_to_tentative_parse (parser);
+ cp_parser_commit_to_topmost_tentative_parse (parser);
/* Look for the type-name again. We are not responsible for
checking that it matches the first type-name. */
@@ -24346,6 +24348,32 @@ cp_parser_commit_to_tentative_parse (cp_parser* pa
}
}
+/* Commit to the topmost currently active tentative parse.
+
+ Note that this function shouldn't be called when there are
+ irreversible side-effects while in a tentative state. For
+ example, we shouldn't create a permanent entry in the symbol
+ table, or issue an error message that might not apply if the
+ tentative parse is aborted. */
+
+static void
+cp_parser_commit_to_topmost_tentative_parse (cp_parser* parser)
+{
+ cp_parser_context *context = parser->context;
+ cp_lexer *lexer = parser->lexer;
+
+ if (context)
+ {
+ if (context->status == CP_PARSER_STATUS_KIND_COMMITTED)
+ return;
+ context->status = CP_PARSER_STATUS_KIND_COMMITTED;
+
+ while (!cp_lexer_saving_tokens (lexer))
+ lexer = lexer->next;
+ cp_lexer_commit_tokens (lexer);
+ }
+}
+
/* Abort the currently active tentative parse. All consumed tokens
will be rolled back, and no diagnostics will be issued. */
Index: testsuite/g++.dg/cpp0x/decltype57.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype57.C (revision 0)
+++ testsuite/g++.dg/cpp0x/decltype57.C (working copy)
@@ -0,0 +1,8 @@
+// PR c++/58633
+// { dg-do compile { target c++11 } }
+
+void foo(int i)
+{
+ typedef int I;
+ decltype(i.I::~I())* p;
+}