https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90210

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:cf7dae01734eea0dfb4c387e4cd40e1f9a682f56

commit r11-3574-gcf7dae01734eea0dfb4c387e4cd40e1f9a682f56
Author: Marek Polacek <pola...@redhat.com>
Date:   Fri Sep 18 16:57:34 2020 -0400

    c++: CTAD and explicit deduction guides for copy-list-init [PR90210]

    This PR points out that we accept

      template<typename T> struct tuple { tuple(T); }; // #1
      template<typename T> explicit tuple(T t) -> tuple<T>; // #2
      tuple t = { 1 };

    despite the 'explicit' deduction guide in a copy-list-initialization
    context.  That's because in deduction_guides_for we first find the
    user-defined deduction guide (#2), and then ctor_deduction_guides_for
    creates artificial deduction guides: one from the tuple(T) constructor and
    a copy guide.  So we end up with these three guides:

      (1) template<class T> tuple(T) -> tuple<T> [DECL_NONCONVERTING_P]
      (2) template<class T> tuple(tuple<T>) -> tuple<T>
      (3) template<class T> tuple(T) -> tuple<T>

    Then, in do_class_deduction, we prune this set, and get rid of (1).
    Then overload resolution selects (3) and we succeed.

    But [over.match.list]p1 says "In copy-list-initialization, if an explicit
    constructor is chosen, the initialization is ill-formed."  It also goes
    on to say that this differs from other situations where only converting
    constructors are considered for copy-initialization.  Therefore for
    list-initialization we consider explicit constructors and complain if one
    is chosen.  E.g. convert_like_internal/ck_user can give an error.

    So my logic runs that we should not prune the deduction_guides_for guides
    in a copy-list-initialization context, and only complain if we actually
    choose an explicit deduction guide.  This matches clang++/EDG/msvc++.

    gcc/cp/ChangeLog:

            PR c++/90210
            * pt.c (do_class_deduction): Don't prune explicit deduction guides
            in copy-list-initialization.  In copy-list-initialization, if an
            explicit deduction guide was selected, give an error.

    gcc/testsuite/ChangeLog:

            PR c++/90210
            * g++.dg/cpp1z/class-deduction73.C: New test.

Reply via email to