diff mbox

PR c++/51191 - ICE on alias of alias template instantiation

Message ID m3ipmisbj4.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Nov. 17, 2011, 9:07 p.m. UTC
Hello,

In the example of the patch below, we crash when trying to print the
alias of alias template instantiation 'Alias'.  This is because
alias_template_specialization_p carelessly looks at
CLASSTYPE_TEMPLATE_INFO first, while TYPE_TEMPLATE_INFO is NULL in
this case.

Fixed thus, bootstrapped and tested on x86_64-unknown-linux-gnu
against trunk.

gcc/cp/

	PR c++/51191 - ICE while printing alias of alias instantiation
	* pt.c (alias_template_specialization_p): Don't crash on an alias
	of template alias instantiation.

gcc/testsuite/

	PR c++/51191 - ICE while printing alias of alias instantiation
	* g++.dg/cpp0x/alias-decl-13.C: New test.
---
 gcc/cp/pt.c                                |    3 ++-
 gcc/testsuite/g++.dg/cpp0x/alias-decl-13.C |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-13.C
diff mbox

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9738026..ac5d394 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5310,7 +5310,8 @@  alias_template_specialization_p (tree t)
 {
   if (t == NULL_TREE)
     return false;
-  return (primary_template_instantiation_p (t)
+  return (TYPE_TEMPLATE_INFO (t)
+	  && primary_template_instantiation_p (t)
 	  && DECL_ALIAS_TEMPLATE_P (TYPE_TI_TEMPLATE (t)));
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-13.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-13.C
new file mode 100644
index 0000000..8555154
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-13.C
@@ -0,0 +1,24 @@ 
+// Origin PR c++/51191
+// { dg-options "-std=c++0x" }
+
+template< class T >
+class ClassTemplate {};
+
+template< class T >
+struct Metafunction {
+  typedef T type;
+};
+
+template< class T >
+using TemplateAlias = ClassTemplate< typename Metafunction<T>::type >;
+
+using Alias = TemplateAlias<int>;
+
+template< class T >
+void f( TemplateAlias<T> );
+
+int main()
+{
+  Alias x;
+  f( x ); // { dg-error "no matching function for call to|f" }
+}