2017-05-23 Nathan Sidwell <nathan@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.
===================================================================
@@ -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> ();
===================================================================
@@ -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();