From e5cc0d5453f3a79902522c719fe4fd5765b689b3 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 19 Mar 2018 20:34:45 +0000 Subject: [PATCH] re PR c++/84925 (ICE with segfault in __PRETTY_FUNCTION__) PR c++/84925 * pt.c (enclosing_instantiation_of): Check if fn is null. * g++.dg/cpp1z/lambda-__func__.C: New test. From-SVN: r258660 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1z/lambda-__func__.C | 13 +++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/lambda-__func__.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 194b4689082..712d4d8bc2d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-03-19 Marek Polacek + + PR c++/84925 + * pt.c (enclosing_instantiation_of): Check if fn is null. + 2018-03-16 Jason Merrill PR c++/71834 - template-id with too few arguments. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 086cdc20781..21a4de57745 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12917,7 +12917,7 @@ enclosing_instantiation_of (tree otctx) for (; flambda_count < lambda_count && fn && LAMBDA_FUNCTION_P (fn); fn = decl_function_context (fn)) ++flambda_count; - if (DECL_TEMPLATE_INFO (fn) + if ((fn && DECL_TEMPLATE_INFO (fn)) ? most_general_template (fn) != most_general_template (tctx) : fn != tctx) continue; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e3309b33d1b..882dc9ab92d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-19 Marek Polacek + + PR c++/84925 + * g++.dg/cpp1z/lambda-__func__.C: New test. + 2018-03-19 Maxim Ostapenko PR sanitizer/78651 diff --git a/gcc/testsuite/g++.dg/cpp1z/lambda-__func__.C b/gcc/testsuite/g++.dg/cpp1z/lambda-__func__.C new file mode 100644 index 00000000000..d5d1c1cb7b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/lambda-__func__.C @@ -0,0 +1,13 @@ +// PR c++/84925 +// { dg-options "-std=c++17" } + +template +struct A { + static const int value = 0; + static auto constexpr fn = [] { return __func__; }; +}; + +template +int x = A::value; + +auto s = x; -- 2.30.2