From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 3ADBD3980436; Thu, 20 May 2021 21:35:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3ADBD3980436 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9852] c++: deduction guide using alias [PR99180] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: e41d610696b81e72d1d06db176b281424e32fc23 X-Git-Newrev: 92e9b2a995f718f1c2ab1cd0840b439c24d3535f Message-Id: <20210520213541.3ADBD3980436@sourceware.org> Date: Thu, 20 May 2021 21:35:41 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 21:35:41 -0000 https://gcc.gnu.org/g:92e9b2a995f718f1c2ab1cd0840b439c24d3535f commit r10-9852-g92e9b2a995f718f1c2ab1cd0840b439c24d3535f Author: Jason Merrill Date: Fri Apr 9 18:02:38 2021 -0400 c++: deduction guide using alias [PR99180] alias_ctad_tweaks was expecting that all deduction guides for the class would be suitable for deduction from the alias definition; in this case, the deduction guide uses 'true' and the alias B uses 'false', so deduction fails. But that's OK, we just don't use that deduction guide. I also noticed that we were giving up on deduction entirely if substitution failed for some guide; we should only give up on that particular deduction guide. We ought to give a better diagnostic about this case when deduction fails, but that can wait. gcc/cp/ChangeLog: PR c++/99180 PR c++/93295 PR c++/93867 PR c++/99118 PR c++/96873 * pt.c (alias_ctad_tweaks): Handle failure better. gcc/testsuite/ChangeLog: PR c++/99180 PR c++/93295 PR c++/93867 PR c++/95486 * g++.dg/cpp2a/class-deduction-alias5.C: New test. * g++.dg/cpp2a/class-deduction-alias6.C: New test. * g++.dg/cpp2a/class-deduction-alias7.C: New test. * g++.dg/cpp2a/class-deduction-alias8.C: New test. Diff: --- gcc/cp/pt.c | 7 +++-- .../g++.dg/cpp2a/class-deduction-alias5.C | 18 ++++++++++++ .../g++.dg/cpp2a/class-deduction-alias6.C | 11 ++++++++ .../g++.dg/cpp2a/class-deduction-alias7.C | 32 ++++++++++++++++++++++ .../g++.dg/cpp2a/class-deduction-alias8.C | 14 ++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 79d648b6ba4..fb32313488a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -28808,7 +28808,8 @@ alias_ctad_tweaks (tree tmpl, tree uguides) unsigned len = TREE_VEC_LENGTH (ftparms); tree targs = make_tree_vec (len); int err = unify (ftparms, targs, ret, utype, UNIFY_ALLOW_NONE, false); - gcc_assert (!err); + if (err) + continue; /* The number of parms for f' is the number of parms for A plus non-deduced parms of f. */ @@ -28841,7 +28842,7 @@ alias_ctad_tweaks (tree tmpl, tree uguides) guideness, and explicit-specifier. */ tree g = tsubst_decl (DECL_TEMPLATE_RESULT (f), targs, complain); if (g == error_mark_node) - return error_mark_node; + continue; DECL_USE_TEMPLATE (g) = 0; fprime = build_template_decl (g, gtparms, false); DECL_TEMPLATE_RESULT (fprime) = g; @@ -28855,7 +28856,7 @@ alias_ctad_tweaks (tree tmpl, tree uguides) if (ci) ci = tsubst_constraint_info (ci, targs, complain, in_decl); if (ci == error_mark_node) - return error_mark_node; + continue; /* Add a constraint that the return type matches the instantiation of A with the same template arguments. */ diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias5.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias5.C new file mode 100644 index 00000000000..69143a3277b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias5.C @@ -0,0 +1,18 @@ +// PR c++/99180 +// { dg-do compile { target c++17 } } + +template +struct A { + A(Ts...) {} +}; + +template +using B = A; + +template +A(Ts...) -> A; + +int main() { + B{}; // { dg-error "alias" "" { target c++17_down } } + return 0; +} diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias6.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias6.C new file mode 100644 index 00000000000..26a38641ab3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias6.C @@ -0,0 +1,11 @@ +// PR c++/93295 +// { dg-do compile { target c++20 } } + +template +struct Foo { + Foo(T) {} +}; + +template Foo(T) -> Foo; +template using Bar = Foo; +Bar b{0}; diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias7.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias7.C new file mode 100644 index 00000000000..0d8bff7610d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias7.C @@ -0,0 +1,32 @@ +// PR c++/93867 +// { dg-do compile { target c++20 } } + +template +struct basic_fixed_string +{ + constexpr basic_fixed_string(const CharT *p) { + for (int i = 0; i < N; ++i) { + m_data[i] = p[i]; + } + } + + CharT m_data[N] {}; +}; + +template +basic_fixed_string(const CharT (&)[N]) -> basic_fixed_string; + +template +using fixed_string = basic_fixed_string; + +template +constexpr int foo() +{ + return 42; +} + +int main(int argc, char const *argv[]) +{ + foo<"hello">(); + return 0; +} diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias8.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias8.C new file mode 100644 index 00000000000..ec005956fa6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias8.C @@ -0,0 +1,14 @@ +// PR c++/95486 +// { dg-do compile { target c++20 } } + +template +struct X { X(U) requires __is_same(U, int) {} }; + +template +X(U) -> X; + +template +using Y = X; + +Y y{1}; +Y z{'a'}; // { dg-error "failed|no match" }