This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/35405
- From: Dodji Seketeli <dodji at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Tue, 18 Nov 2008 13:09:13 +0100
- Subject: [PATCH] PR c++/35405
Hello,
This is an obvious fix to a crash happening because we are
de-referencing NULL pointers.
The patch passes regtests on trunk for the x86_64 platform, and I am
about to test it on the 4_3 branch as well. OK to apply to those two
branches assuming it passes regtests on 4_3 ?
Cheers,
Dodji.
gcc/cp/ChangeLog/
2008-11-18 Dodji Seketeli <dodji@redhat.com>
PR c++/35405
* pt.c (lookup_template_class): Check pointers before dereferencing
Them.
* error.c (dump_template_decl): Likewise.
gcc/testsuite/ChangeLog:
2008-11-18 Dodji Seketeli <dodji@redhat.com>
PR c++/35405
* g++.dg/template/crash84.C: New test.
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 3aa9b59..a2db157 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1044,11 +1044,13 @@ dump_template_decl (tree t, int flags)
}
}
- if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
+ if (DECL_TEMPLATE_RESULT (t)
+ && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
dump_type (TREE_TYPE (t),
((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
| (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0)));
- else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
+ else if (DECL_TEMPLATE_RESULT (t)
+ && TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
dump_decl (DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME);
else
{
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 13a2361..29a5306 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5585,6 +5585,7 @@ lookup_template_class (tree d1,
d1 = DECL_NAME (templ);
}
else if (TREE_CODE (d1) == TEMPLATE_DECL
+ && DECL_TEMPLATE_RESULT (d1)
&& TREE_CODE (DECL_TEMPLATE_RESULT (d1)) == TYPE_DECL)
{
templ = d1;
diff --git a/gcc/testsuite/g++.dg/template/crash84.C b/gcc/testsuite/g++.dg/template/crash84.C
new file mode 100644
index 0000000..f622aaa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/crash84.C
@@ -0,0 +1,19 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/35405
+// { dg-do compile }
+
+template<typename T> struct a
+{
+ template <template <typename> class C, typename X, C<X>* =0>
+ struct b // { dg-error "class C' is not a template|is not a valid type" }
+ {
+ };
+};
+
+void
+foo ()
+{
+ a<int> v; // { dg-message "instantiated from here" }
+}
+
+