From: Nathan Sidwell Date: Fri, 16 Oct 2020 17:22:16 +0000 (-0700) Subject: c++: Fix nullptr deref [pr97460[ X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ccb4f20cbee1756c464033bbdda2f27b6aa2a63f;p=gcc.git c++: Fix nullptr deref [pr97460[ My changes to friend handling meant that there are now cases where a friend doesn't get a lang-specific object. So we need to check there is one before looking inside it. PR c++/97460 gcc/cp/ * pt.c (push_template_decl): Check DECL_LANG_SPECIFIC in friend case. gcc/testsuite/ * g++.dg/template/pr97460.C: New. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2a9a8fafaca..dc664ec3798 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5877,7 +5877,8 @@ push_template_decl (tree decl, bool is_friend) || TREE_CODE (ctx) == FUNCTION_DECL || (CLASS_TYPE_P (ctx) && TYPE_BEING_DEFINED (ctx)) || (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (TREE_TYPE (decl))) - || (is_friend && !DECL_TEMPLATE_INFO (decl))) + || (is_friend && !(DECL_LANG_SPECIFIC (decl) + && DECL_TEMPLATE_INFO (decl)))) { if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl) diff --git a/gcc/testsuite/g++.dg/template/pr97460.C b/gcc/testsuite/g++.dg/template/pr97460.C new file mode 100644 index 00000000000..6dea4898997 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr97460.C @@ -0,0 +1,9 @@ +// PR 97460 +// ICE, null dereference + +class io_context { + template class basic_executor_type; +}; +template class io_context::basic_executor_type { + template friend class basic_executor_type; +};