Fix c++/67337 (segfault in mangle.c)
authortrippels <trippels@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Dec 2015 19:57:55 +0000 (19:57 +0000)
committertrippels <trippels@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 2 Dec 2015 19:57:55 +0000 (19:57 +0000)
PR c++/67337
* mangle.c (write_template_prefix): Guard against context==NULL.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231203 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 6d344ff..ce26e5d 100644 (file)
@@ -1,3 +1,8 @@
+2015-12-02  Markus Trippelsdorf  <markus@trippelsdorf.de>
+
+       PR c++/67337
+       * mangle.c (write_template_prefix): Guard against context==NULL.
+
 2015-12-02  Jason Merrill  <jason@redhat.com>
 
        * call.c (build_new_op_1): Don't fold arguments to
index 6f8bf68..3ff3066 100644 (file)
@@ -1145,7 +1145,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);
+}