Commit 9c62c1f3 by Jason Merrill Committed by Jason Merrill

PR c++/70735 - generic lambda and local static variable

	* pt.c (tsubst_copy): Just return a local variable from
	non-template context.  Don't call rest_of_decl_compilation for
	duplicated static locals.
	(tsubst_decl): Set DECL_CONTEXT of local static from another
	function.

From-SVN: r236615
parent 26d6ae55
2016-05-23 Jason Merrill <jason@redhat.com>
PR c++/70735
* pt.c (tsubst_copy): Just return a local variable from
non-template context. Don't call rest_of_decl_compilation for
duplicated static locals.
(tsubst_decl): Set DECL_CONTEXT of local static from another
function.
2016-05-23 Paolo Carlini <paolo.carlini@oracle.com> 2016-05-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/70972 PR c++/70972
......
...@@ -12281,6 +12281,14 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) ...@@ -12281,6 +12281,14 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
local_p = true; local_p = true;
/* Subsequent calls to pushdecl will fill this in. */ /* Subsequent calls to pushdecl will fill this in. */
ctx = NULL_TREE; ctx = NULL_TREE;
/* Unless this is a reference to a static variable from an
enclosing function, in which case we need to fill it in now. */
if (TREE_STATIC (t))
{
tree fn = tsubst (DECL_CONTEXT (t), args, complain, in_decl);
if (fn != current_function_decl)
ctx = fn;
}
spec = retrieve_local_specialization (t); spec = retrieve_local_specialization (t);
} }
/* If we already have the specialization we need, there is /* If we already have the specialization we need, there is
...@@ -13992,7 +14000,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) ...@@ -13992,7 +14000,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
case FUNCTION_DECL: case FUNCTION_DECL:
if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)) if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t))
r = tsubst (t, args, complain, in_decl); r = tsubst (t, args, complain, in_decl);
else if (local_variable_p (t)) else if (local_variable_p (t)
&& uses_template_parms (DECL_CONTEXT (t)))
{ {
r = retrieve_local_specialization (t); r = retrieve_local_specialization (t);
if (r == NULL_TREE) if (r == NULL_TREE)
...@@ -14036,14 +14045,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) ...@@ -14036,14 +14045,9 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
gcc_assert (cp_unevaluated_operand || TREE_STATIC (r) gcc_assert (cp_unevaluated_operand || TREE_STATIC (r)
|| decl_constant_var_p (r) || decl_constant_var_p (r)
|| errorcount || sorrycount); || errorcount || sorrycount);
if (!processing_template_decl) if (!processing_template_decl
{ && !TREE_STATIC (r))
if (TREE_STATIC (r)) r = process_outer_var_ref (r, complain);
rest_of_decl_compilation (r, toplevel_bindings_p (),
at_eof);
else
r = process_outer_var_ref (r, complain);
}
} }
/* Remember this for subsequent uses. */ /* Remember this for subsequent uses. */
if (local_specializations) if (local_specializations)
......
// PR c++/70735
// { dg-do run { target c++1y } }
int main()
{
static int a;
auto f = [](auto) { return a; };
if (f(0) != 0)
__builtin_abort();
a = 1;
if (f(0) != 1)
__builtin_abort();
}
// PR c++/70735
// { dg-do run { target c++1y } }
template <class T>
static void g()
{
static int a;
auto f = [](auto) { return a; };
if (f(0) != 0)
__builtin_abort();
a = 1;
if (f(0) != 1)
__builtin_abort();
}
int main()
{
g<int>();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment