aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-10-16 10:22:16 -0700
committerNathan Sidwell <nathan@acm.org>2020-10-16 10:22:16 -0700
commitccb4f20cbee1756c464033bbdda2f27b6aa2a63f (patch)
tree141fbcac7c4ea07cb5499361bfab57e40a495b6d
parenta16da48bf19bb139e5461e5b5b7f072d5369b054 (diff)
downloadgcc-ccb4f20cbee1756c464033bbdda2f27b6aa2a63f.zip
gcc-ccb4f20cbee1756c464033bbdda2f27b6aa2a63f.tar.gz
gcc-ccb4f20cbee1756c464033bbdda2f27b6aa2a63f.tar.bz2
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.
-rw-r--r--gcc/cp/pt.c3
-rw-r--r--gcc/testsuite/g++.dg/template/pr97460.C9
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2a9a8fa..dc664ec 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 0000000..6dea489
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr97460.C
@@ -0,0 +1,9 @@
+// PR 97460
+// ICE, null dereference
+
+class io_context {
+ template <int> class basic_executor_type;
+};
+template <int> class io_context::basic_executor_type {
+ template <int> friend class basic_executor_type;
+};