This patch fixes 80866, a regression I introduced. The parser stashes template-ids when tentatively parsing, such ids can contain lookups. We need to mark the lookup as 'kept', otherwise the first parse could say 'I'm done with this' and recycle it prematurely.

Applied to trunk.

nathan
--
Nathan Sidwell
2017-05-23  Nathan Sidwell  <nat...@acm.org>

	PR c++/80866
	* parser.c (cp_parser_template_id): Keep the lookup when stashing
	the template_id.

	PR c++/80866
	* g++.dg/parse/pr80866.C: New.

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 248372)
+++ cp/parser.c	(working copy)
@@ -15570,6 +15570,11 @@ cp_parser_template_id (cp_parser *parser
 	= make_location (token->location, token->location, finish_loc);
       token->location = combined_loc;
 
+      /* We must mark the lookup as kept, so we don't throw it away on
+	 the first parse.  */
+      if (is_overloaded_fn (template_id))
+	lookup_keep (get_fns (template_id), true);
+
       /* Retrieve any deferred checks.  Do not pop this access checks yet
 	 so the memory will not be reclaimed during token replacing below.  */
       token->u.tree_check_value = ggc_cleared_alloc<struct tree_check> ();
Index: testsuite/g++.dg/parse/pr80866.C
===================================================================
--- testsuite/g++.dg/parse/pr80866.C	(revision 0)
+++ testsuite/g++.dg/parse/pr80866.C	(working copy)
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+// PR 80866 recycled a lookup too soon.
+
+void pow();
+namespace math {
+  template <typename T> void pow(T);
+}
+using namespace math;
+
+decltype(pow<>(0)) z();

Reply via email to