From 689f867c9c8668f864520372562f8e1b3ca7137c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 19 Jan 2017 23:43:13 -0500 Subject: [PATCH] US 19 - deduction guides and constructors * call.c (joust): Prefer deduction guides to constructors. * pt.c (build_deduction_guide): Set DECL_ARTIFICIAL. (deduction_guide_p): Check DECL_P. From-SVN: r244681 --- gcc/cp/ChangeLog | 5 ++++ gcc/cp/call.c | 12 ++++++++++ gcc/cp/pt.c | 7 ++++-- .../g++.dg/cpp1z/class-deduction25.C | 24 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction25.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 90e230fc344..e16853971fb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2017-01-19 Jason Merrill + US 19 - deduction guides and constructors + * call.c (joust): Prefer deduction guides to constructors. + * pt.c (build_deduction_guide): Set DECL_ARTIFICIAL. + (deduction_guide_p): Check DECL_P. + * decl.c (check_initializer): Always use build_aggr_init for array decomposition. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 88d83dd8a5d..0059a395ae4 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -9633,6 +9633,18 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn, return winner; } + /* F1 is generated from a deduction-guide (13.3.1.8) and F2 is not */ + if (deduction_guide_p (cand1->fn)) + { + gcc_assert (deduction_guide_p (cand2->fn)); + /* We distinguish between candidates from an explicit deduction guide and + candidates built from a constructor based on DECL_ARTIFICIAL. */ + int art1 = DECL_ARTIFICIAL (cand1->fn); + int art2 = DECL_ARTIFICIAL (cand2->fn); + if (art1 != art2) + return art2 - art1; + } + /* or, if not that, F1 is a non-template function and F2 is a template function specialization. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c679133850e..f683727e977 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24776,8 +24776,9 @@ dguide_name_p (tree name) bool deduction_guide_p (tree fn) { - if (tree name = DECL_NAME (fn)) - return dguide_name_p (name); + if (DECL_P (fn)) + if (tree name = DECL_NAME (fn)) + return dguide_name_p (name); return false; } @@ -24981,7 +24982,9 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain) FUNCTION_DECL, dguide_name (type), fntype); DECL_ARGUMENTS (ded_fn) = fargs; + DECL_ARTIFICIAL (ded_fn) = true; tree ded_tmpl = build_template_decl (ded_fn, tparms, /*member*/false); + DECL_ARTIFICIAL (ded_tmpl) = true; DECL_TEMPLATE_RESULT (ded_tmpl) = ded_fn; TREE_TYPE (ded_tmpl) = TREE_TYPE (ded_fn); DECL_TEMPLATE_INFO (ded_fn) = build_template_info (ded_tmpl, targs); diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction25.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction25.C new file mode 100644 index 00000000000..07ab5f5738c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction25.C @@ -0,0 +1,24 @@ +// Testcase from P0512R0 for C++17 NB comment US 19 +// { dg-options -std=c++1z } + +template struct remove_ref; +template struct remove_ref { typedef _Tp type; }; +template struct remove_ref<_Tp&> { typedef _Tp type; }; +template struct remove_ref<_Tp&&> { typedef _Tp type; }; +template using remove_ref_t = typename remove_ref<_Tp>::type; + +template struct A { + A(T, int*); // #1 + A(A&, int*); // #2 + enum { value }; +}; +template::value> A(T&&, int*) -> A; //#3 + +A a{1,0}; // uses #1 to deduce A and initializes with #1 +A b{a,0}; // uses #3 (not #2) to deduce A&> and initializes with #1 + +template struct same; +template struct same {}; + +same> s1; +same&>> s2; -- 2.30.2