From 787f3ebf00d4e1f741ea03b6ddea9cf07a6f94ac Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 3 Feb 2021 21:56:59 -0500 Subject: [PATCH] c++: No aggregate CTAD with explicit dguide [PR98802] In my implementation of P2082R1 I missed this piece: the aggregate deduction candidate is not generated if the class has user-written deduction guides. gcc/cp/ChangeLog: PR c++/98802 * pt.c (do_class_deduction): No aggregate guide if any_dguides_p. gcc/testsuite/ChangeLog: PR c++/98802 * g++.dg/cpp1z/class-deduction78.C: New test. --- gcc/cp/pt.c | 5 +++-- .../g++.dg/cpp1z/class-deduction78.C | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction78.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index af7c67af29f..3605b67e424 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -29272,8 +29272,9 @@ do_class_deduction (tree ptype, tree tmpl, tree init, } } - if (tree guide = maybe_aggr_guide (tmpl, init, args)) - cands = lookup_add (guide, cands); + if (!any_dguides_p) + if (tree guide = maybe_aggr_guide (tmpl, init, args)) + cands = lookup_add (guide, cands); tree call = error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction78.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction78.C new file mode 100644 index 00000000000..651645486d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction78.C @@ -0,0 +1,20 @@ +// PR c++/98802 +// { dg-do compile { target c++17 } } + +using size_t = decltype(sizeof(42)); + +template +struct List { + T head; + List tail; +}; + +template +struct List {}; + +template List(T) -> List; +template List(T, List) -> List; + +int main() { + auto list2 = List{0, List{1, List{2}}}; +} -- 2.30.2