From: Jason Merrill Date: Tue, 13 Mar 2018 20:22:31 +0000 (-0400) Subject: PR c++/82565 - ICE with concepts and generic lambda. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=515f874faf45628b1b86da81964f2049f7406326;p=gcc.git PR c++/82565 - ICE with concepts and generic lambda. * pt.c (instantiate_decl): Clear fn_context for lambdas. From-SVN: r258502 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 23079f05923..da81495e8a4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-03-13 Jason Merrill + + PR c++/82565 - ICE with concepts and generic lambda. + * pt.c (instantiate_decl): Clear fn_context for lambdas. + 2018-03-13 Jason Merrill PR c++/84720 - ICE with rvalue ref non-type argument. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a16aef6bf58..d720c33cf0a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -23460,6 +23460,9 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) bool push_to_top, nested; tree fn_context; fn_context = decl_function_context (d); + if (LAMBDA_FUNCTION_P (d)) + /* tsubst_lambda_expr resolved any references to enclosing functions. */ + fn_context = NULL_TREE; nested = current_function_decl != NULL_TREE; push_to_top = !(nested && fn_context == current_function_decl); diff --git a/gcc/testsuite/g++.dg/concepts/lambda1.C b/gcc/testsuite/g++.dg/concepts/lambda1.C new file mode 100644 index 00000000000..a77e65459b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/lambda1.C @@ -0,0 +1,32 @@ +// PR c++/82565 +// { dg-do compile { target c++14 } } +// { dg-additional-options -fconcepts } + +struct string +{ + string(); + string(const char *); + bool empty() const; +}; + +template +concept bool Concept() { + return requires(T t, const string& s) { + { t(s) } -> ReturnType; + }; +} + +struct test { + string _str; + + template + requires Concept() + decltype(auto) visit(Visitor&& visitor) const { + return visitor(_str); + } + +}; + +int main() { + test().visit([] (auto& x) { return x.empty(); }); +}