]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix c++/67337 (segfault in mangle.c)
authorMarkus Trippelsdorf <markus@trippelsdorf.de>
Fri, 4 Dec 2015 11:46:39 +0000 (11:46 +0000)
committerMarkus Trippelsdorf <trippels@gcc.gnu.org>
Fri, 4 Dec 2015 11:46:39 +0000 (11:46 +0000)
PR c++/67337
* mangle.c (write_template_prefix): Guard against context==NULL.

From-SVN: r231258

gcc/cp/ChangeLog
gcc/cp/mangle.c
gcc/testsuite/g++.dg/template/pr67337.C [new file with mode: 0644]

index 8fe4ac59b5f3f7f43426251d742b1f1db7924237..ed260f14b400940f0ad2ea5cff58f0df67a6c91d 100644 (file)
@@ -1,3 +1,8 @@
+2015-12-04  Markus Trippelsdorf  <markus@trippelsdorf.de>
+
+       PR c++/67337
+       * mangle.c (write_template_prefix): Guard against context==NULL.
+
 2015-08-17  Jason Merrill  <jason@redhat.com>
 
        PR c++/66957
index c9b1c5f8eb07d401d9ed2395ff80ddc365071ae7..3a22b0dc5841bf3a050c2d98632cab11fa89b09f 100644 (file)
@@ -1118,7 +1118,7 @@ write_template_prefix (const tree node)
      So, for the example above, `Outer<int>::Inner' is represented as a
      substitution candidate by a TREE_LIST whose purpose is `Outer<int>'
      and whose value is `Outer<T>::Inner<U>'.  */
-  if (TYPE_P (context))
+  if (context && TYPE_P (context))
     substitution = build_tree_list (context, templ);
   else
     substitution = templ;
diff --git a/gcc/testsuite/g++.dg/template/pr67337.C b/gcc/testsuite/g++.dg/template/pr67337.C
new file mode 100644 (file)
index 0000000..df2651b
--- /dev/null
@@ -0,0 +1,25 @@
+template <class> class A
+{
+  void m_fn1 (int *, int);
+};
+
+template <class> class B
+{
+public:
+  typedef int Type;
+};
+
+template <class> class C
+{
+public:
+  C (int);
+  template <template <class> class T> void m_fn2 (typename T<void>::Type);
+};
+
+template <>
+void
+A<int>::m_fn1 (int *, int)
+{
+  C<int> a (0);
+  a.m_fn2<B> (0);
+}