[PATCH] PR c++/54466 - ICE with alias template which type-id is const qualified
Dodji Seketeli
dodji@redhat.com
Sat Oct 27 12:10:00 GMT 2012
Hello,
Consider this short example:
template<typename T>
struct X { };
template<typename T>
using Y = const X<T>;
using Z = Y<int>;
G++ crashes in lookup_class_template_1 while trying to build the alias
template instantiation Y<int>.
I think this is indirectly due to the fact that lookup_class_template_1
can now yield a const qualified type like 'const X<T>'.
As a consequence, the code in lookup_template_class_1 that was trying
to access the TYPE_STUB_DECL field of the result of
lookup_template_class_1 should now be adjusted to access the
TYPE_STUB_DECL of the main variant of the resulting type instead;
because qualified types (constructed with build_qualified_type)
have their TYPE_STUB_DECL set to NULL.
Fixed thus and tested on x86_64-unknown-linux-gnu against trunk.
gcc/cp
PR c++/54466
* pt.c (lookup_template_class_1): TYPE_STUB_DECL should be
accessed on the main variant of the type.
gcc/testsuite/
* g++.dg/cpp0x/alias-decl-25.C: New test file.
In the example of this patch, g++ crashes when trying to build the
alias template Y<int
---
gcc/cp/pt.c | 5 +++--
gcc/testsuite/g++.dg/cpp0x/alias-decl-25.C | 10 ++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-25.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1ff1c73..d442f01 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7371,10 +7371,11 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
if (CLASS_TYPE_P (template_type))
{
+ tree tt = TYPE_MAIN_VARIANT (template_type);
TREE_PRIVATE (type_decl)
- = TREE_PRIVATE (TYPE_STUB_DECL (template_type));
+ = TREE_PRIVATE (TYPE_STUB_DECL (tt));
TREE_PROTECTED (type_decl)
- = TREE_PROTECTED (TYPE_STUB_DECL (template_type));
+ = TREE_PROTECTED (TYPE_STUB_DECL (tt));
if (CLASSTYPE_VISIBILITY_SPECIFIED (template_type))
{
DECL_VISIBILITY_SPECIFIED (type_decl) = 1;
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-25.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-25.C
new file mode 100644
index 0000000..dd4cc02
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-25.C
@@ -0,0 +1,10 @@
+// Origin: PR c++/54466
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+ struct X { };
+
+template<typename T>
+ using Y = const X<T>;
+
+using Z = Y<int>;
--
Dodji
More information about the Gcc-patches
mailing list