From 5d4d0be8132cb837ce075e28f14d7ef8dcc02767 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 18 Jun 2018 14:16:38 -0400 Subject: [PATCH] PR c++/86171 - ICE with recursive alias instantiation. * pt.c (tsubst_decl): Handle recursive alias instantiation. From-SVN: r261709 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 10 +++++++++- gcc/testsuite/g++.dg/cpp0x/alias-decl-65.C | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-65.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c3b5bc628b0..b1a449f91e2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-06-18 Jason Merrill + + PR c++/86171 - ICE with recursive alias instantiation. + * pt.c (tsubst_decl): Handle recursive alias instantiation. + 2018-06-18 Paolo Carlini * decl.c (duplicate_decls): Consistently use DECL_SOURCE_LOCATION diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4ee84b201e9..6e590d4d342 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13639,7 +13639,6 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) } /* Create a new node for the specialization we need. */ - r = copy_decl (t); if (type == NULL_TREE) { if (is_typedef_decl (t)) @@ -13664,7 +13663,16 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) sub_args = strip_innermost_template_args (args, extra); } type = tsubst (type, sub_args, complain, in_decl); + /* Substituting the type might have recursively instantiated this + same alias (c++/86171). */ + if (gen_tmpl && DECL_ALIAS_TEMPLATE_P (gen_tmpl) + && (spec = retrieve_specialization (gen_tmpl, argvec, hash))) + { + r = spec; + break; + } } + r = copy_decl (t); if (VAR_P (r)) { DECL_INITIALIZED_P (r) = 0; diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-65.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-65.C new file mode 100644 index 00000000000..e320f3eedd0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-65.C @@ -0,0 +1,10 @@ +// PR c++/86171 +// { dg-do compile { target c++11 } } + +template struct A; +template using B = typename A::X; +template struct A { + typedef int X; + typedef B U; +}; +B b; -- 2.30.2