From: Patrick Palka Date: Thu, 24 Jun 2021 17:11:44 +0000 (-0400) Subject: c++: alias CTAD and aggregate deduction cand [PR98832] X-Git-Tag: releases/gcc-11.2.0~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=660cbbae327fbfa315e26d286b03efffc3c21cb5;p=thirdparty%2Fgcc.git c++: alias CTAD and aggregate deduction cand [PR98832] During alias CTAD, we're accidentally ignoring the aggregate deduction candidate for the underlying template because this guide is added separately via maybe_aggr_guide (which doesn't yet handle alias templates) instead of via deduction_guides_for (which does). This patch makes maybe_aggr_guide handle alias templates in a manner similar to deduction_guides_for. PR c++/98832 gcc/cp/ChangeLog: * pt.c (maybe_aggr_guide): Handle alias templates appropriately. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias9.C: New test. (cherry picked from commit c761be53f6b62e22ac5de18c4aaf88648f64f5b7) --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e77d7c3eb984..af06c61e4f42 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -28900,6 +28900,8 @@ is_spec_or_derived (tree etype, tree tmpl) return !err; } +static tree alias_ctad_tweaks (tree, tree); + /* Return a C++20 aggregate deduction candidate for TYPE initialized from INIT. */ @@ -28912,6 +28914,15 @@ maybe_aggr_guide (tree tmpl, tree init, vec *args) if (init == NULL_TREE) return NULL_TREE; + if (DECL_ALIAS_TEMPLATE_P (tmpl)) + { + tree under = DECL_ORIGINAL_TYPE (DECL_TEMPLATE_RESULT (tmpl)); + tree tinfo = get_template_info (under); + if (tree guide = maybe_aggr_guide (TI_TEMPLATE (tinfo), init, args)) + return alias_ctad_tweaks (tmpl, guide); + return NULL_TREE; + } + /* We might be creating a guide for a class member template, e.g., template struct A { diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C new file mode 100644 index 000000000000..5cc7b7c1a801 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C @@ -0,0 +1,6 @@ +// PR c++/98832 +// { dg-do compile { target c++20 } } + +template struct X { U u; }; +template using Y = X; +Y y{0};