On 6/24/21 11:15 AM, Patrick Palka wrote:
During alias CTAD, we're accidentally ignoring the aggregate deduction
candidate of the underlying template because it's added to the candidate
set separately via maybe_aggr_guide (which doesn't yet handle alias
templates) rather than via deduction_guides_for (which does).  This
patch makes maybe_aggr_guide handle alias templates in a manner similar
to deduction_guides_for.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?

OK.

        PR c++/98832

gcc/cp/ChangeLog:

        * pt.c (maybe_aggr_guide): Handle an alias template.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp2a/class-deduction-alias9.C: New test.
---
  gcc/cp/pt.c                                         | 11 +++++++++++
  gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C |  6 ++++++
  2 files changed, 17 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias9.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index aeb1e8a6f97..db15e4714d5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -28880,6 +28880,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.  */
@@ -28892,6 +28894,15 @@ maybe_aggr_guide (tree tmpl, tree init, vec<tree,va_gc> *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<typename U> 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 00000000000..0aaf203639a
--- /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<class T, class U> struct X{ U u; };
+template<class T> using Y = X<int, T>;
+Y y{0};


Reply via email to