public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
@ 2024-05-22 21:27 s.murthy at outlook dot com
  2024-05-22 21:28 ` [Bug c++/115198] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: s.murthy at outlook dot com @ 2024-05-22 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115198
           Summary: Class template argument deduction fails for copy ctor
                    when used with an alias template if the aliased class
                    template has explicitly defaulted copy ctor
           Product: gcc
           Version: 14.1.0
               URL: https://sigcpp.godbolt.org/z/jjGT8hK8d
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: s.murthy at outlook dot com
  Target Milestone: ---

Class template argument deduction fails when the copy ctor is used with an
alias template if the aliased class template has explicitly defaulted copy
ctor. The error disappears if the explicit defaulted copy ctor is removed (i.e.
have the compiler include the implicitly declared copy ctor).

See repro but I believe this issue manifests at least under the following
conditions:
- All parameters of the alias template have default values
- The copy ctor is used using the alias template without any arguments for the
template parameters and without angle brackets (as you would with a class
directly).

The issue is seen in GCC 10.1 to 14.1 (since C++20s support). I have confirmed
that trunk too has this issue as of this writing. In comparison Clang trunk
(post 18.1) does *not* have this issue.

PS: Please forgive me if this report does not meet expectations. This is my
first time filing an issue here. Also, my search of the issues did not show
another matching issue (and thus my filing).

A repro with different scenarios is at: https://sigcpp.godbolt.org/z/jjGT8hK8d

//repro in short
template<bool B = false, typename T = int>
class C1 
{
public:    
    C1() = default;
    C1(const C1& other) = default;
};

template<typename T = int>
using A1 = C1<false, T>;

C1 c1;
A1 a1(c1); //Error


//same as C1 but with implict copy ctor
template<bool B = false, typename T = int>
class C2 
{
public:    
    C2() = default;
};

template<typename T = int>
using A2 = C2<false, T>;

C2 c2;
A2 a2(c2);  //OK

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
@ 2024-05-22 21:28 ` pinskia at gcc dot gnu.org
  2024-05-22 21:47 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-22 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|https://sigcpp.godbolt.org/ |
                   |z/jjGT8hK8d                 |

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://sigcpp.godbolt.org/z/jjGT8hK8d

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
  2024-05-22 21:28 ` [Bug c++/115198] " pinskia at gcc dot gnu.org
@ 2024-05-22 21:47 ` pinskia at gcc dot gnu.org
  2024-05-22 22:01 ` s.murthy at outlook dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-22 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
   Last reconfirmed|                            |2024-05-22
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
  2024-05-22 21:28 ` [Bug c++/115198] " pinskia at gcc dot gnu.org
  2024-05-22 21:47 ` pinskia at gcc dot gnu.org
@ 2024-05-22 22:01 ` s.murthy at outlook dot com
  2024-05-22 22:02 ` s.murthy at outlook dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: s.murthy at outlook dot com @ 2024-05-22 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Sean Murthy <s.murthy at outlook dot com> ---
For everyone's convenience, attaching here the compiler's error message. The
notes the compiler attached to the error indicate the issue might be with a
possibly erroneous/superfluous deduction guide the compiler itself generates. 

At least that is my speculation based on the first note attached to the error
message.


<source>:57:13: error: class template argument deduction failed:
   57 |     A1 a1(c1);
      |             ^
<source>:57:13: error: call of overloaded 'C1(C1<false, int>&)' is ambiguous
<source>:5:7: note: candidate: 'C1(C1<false, T>)-> C1<false, T> [with T = int]'
    5 | class C1
      |       ^~
<source>:9:5: note: candidate: 'C1(const C1<false, T>&)-> C1<false, T> [with T
= int]'
    9 |     C1(const C1& other) = default;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
                   ` (2 preceding siblings ...)
  2024-05-22 22:01 ` s.murthy at outlook dot com
@ 2024-05-22 22:02 ` s.murthy at outlook dot com
  2024-05-23 15:59 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: s.murthy at outlook dot com @ 2024-05-22 22:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Sean Murthy <s.murthy at outlook dot com> ---
(In reply to Andrew Pinski from comment #2)
> Confirmed.

Thank you for confirming the issue.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
                   ` (3 preceding siblings ...)
  2024-05-22 22:02 ` s.murthy at outlook dot com
@ 2024-05-23 15:59 ` ppalka at gcc dot gnu.org
  2024-06-25 16:59 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-05-23 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
                 CC|                            |ppalka at gcc dot gnu.org
   Target Milestone|---                         |14.2

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
                   ` (4 preceding siblings ...)
  2024-05-23 15:59 ` ppalka at gcc dot gnu.org
@ 2024-06-25 16:59 ` cvs-commit at gcc dot gnu.org
  2024-06-28 21:14 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-25 16:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:06ebb7c6f31fe42ffdea6f51ac1ba1f6b058c090

commit r15-1615-g06ebb7c6f31fe42ffdea6f51ac1ba1f6b058c090
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jun 25 12:59:24 2024 -0400

    c++: alias CTAD and copy deduction guide [PR115198]

    Here we're neglecting to update DECL_NAME during the alias CTAD guide
    transformation, which causes copy_guide_p to return false for the
    transformed copy deduction guide since DECL_NAME is still __dguide_C
    with TREE_TYPE C<B, T> but it should be __dguide_A with TREE_TYPE A<T>
    (i.e. C<false, T>).  This ultimately results in ambiguity during
    overload resolution between the copy deduction guide vs copy ctor guide.

    This patch makes us update DECL_NAME of a transformed guide accordingly
    during alias/inherited CTAD.

            PR c++/115198

    gcc/cp/ChangeLog:

            * pt.cc (alias_ctad_tweaks): Update DECL_NAME of the transformed
            guides.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/class-deduction-alias22.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
                   ` (5 preceding siblings ...)
  2024-06-25 16:59 ` cvs-commit at gcc dot gnu.org
@ 2024-06-28 21:14 ` cvs-commit at gcc dot gnu.org
  2024-06-28 21:16 ` ppalka at gcc dot gnu.org
  2024-06-28 23:06 ` s.murthy at outlook dot com
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-28 21:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

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

commit r14-10358-ga00a8d46ea6ff7130e2493e7bd9824e28e2509b7
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jun 25 12:59:24 2024 -0400

    c++: alias CTAD and copy deduction guide [PR115198]

    Here we're neglecting to update DECL_NAME during the alias CTAD guide
    transformation, which causes copy_guide_p to return false for the
    transformed copy deduction guide since DECL_NAME is still __dguide_C
    with TREE_TYPE C<B, T> but it should be __dguide_A with TREE_TYPE A<T>
    (i.e. C<false, T>).  This ultimately results in ambiguity during
    overload resolution between the copy deduction guide vs copy ctor guide.

    This patch makes us update DECL_NAME of a transformed guide accordingly
    during alias/inherited CTAD.

            PR c++/115198

    gcc/cp/ChangeLog:

            * pt.cc (alias_ctad_tweaks): Update DECL_NAME of the transformed
            guides.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/class-deduction-alias22.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>
    (cherry picked from commit 06ebb7c6f31fe42ffdea6f51ac1ba1f6b058c090)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
                   ` (6 preceding siblings ...)
  2024-06-28 21:14 ` cvs-commit at gcc dot gnu.org
@ 2024-06-28 21:16 ` ppalka at gcc dot gnu.org
  2024-06-28 23:06 ` s.murthy at outlook dot com
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-06-28 21:16 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14.2, thanks for the bug report.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/115198] Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor
  2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
                   ` (7 preceding siblings ...)
  2024-06-28 21:16 ` ppalka at gcc dot gnu.org
@ 2024-06-28 23:06 ` s.murthy at outlook dot com
  8 siblings, 0 replies; 10+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-28 23:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Sean Murthy <s.murthy at outlook dot com> ---
(In reply to Patrick Palka from comment #7)
> Fixed for GCC 14.2, thanks for the bug report.

Neat. I just saw the issues is fixed in trunk on Compiler Explorer. Thank you.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-06-28 23:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-22 21:27 [Bug c++/115198] New: Class template argument deduction fails for copy ctor when used with an alias template if the aliased class template has explicitly defaulted copy ctor s.murthy at outlook dot com
2024-05-22 21:28 ` [Bug c++/115198] " pinskia at gcc dot gnu.org
2024-05-22 21:47 ` pinskia at gcc dot gnu.org
2024-05-22 22:01 ` s.murthy at outlook dot com
2024-05-22 22:02 ` s.murthy at outlook dot com
2024-05-23 15:59 ` ppalka at gcc dot gnu.org
2024-06-25 16:59 ` cvs-commit at gcc dot gnu.org
2024-06-28 21:14 ` cvs-commit at gcc dot gnu.org
2024-06-28 21:16 ` ppalka at gcc dot gnu.org
2024-06-28 23:06 ` s.murthy at outlook dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).