Bug 101883 - class template argument deduction in non-type template parameter allows explicit deduction guide
Summary: class template argument deduction in non-type template parameter allows expli...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 11.3
Assignee: Patrick Palka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-12 15:29 UTC by Barry Revzin
Modified: 2021-10-06 14:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-08-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Revzin 2021-08-12 15:29:25 UTC
Reduced example:

template <class T> struct C { constexpr C(int) {} };
explicit C(int) -> C<int>;

template <C c> struct X { };
X<1> x;

This should fail to compile, because the deduction guide is explicit and so should not be a candidate, but gcc accepts this example.

gcc does correctly reject:

C y = 1;

Which is the same kind of thing.
Comment 1 CVS Commits 2021-08-18 12:39:22 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r12-2990-ga6b3db3e8625a3cba1240f0b5e1a29bd6c68b8ca
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 18 08:37:42 2021 -0400

    c++: ignore explicit dguides during NTTP CTAD [PR101883]
    
    Since (template) argument passing is a copy-initialization context,
    we mustn't consider explicit deduction guides when deducing a CTAD
    placeholder type of an NTTP.
    
            PR c++/101883
    
    gcc/cp/ChangeLog:
    
            * pt.c (convert_template_argument): Pass LOOKUP_IMPLICIT to
            do_auto_deduction.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/nontype-class49.C: New test.
Comment 2 CVS Commits 2021-10-06 14:15:15 UTC
The releases/gcc-11 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:52dd840c5eba25ef54dee3f1c78f371032a7c051

commit r11-9078-g52dd840c5eba25ef54dee3f1c78f371032a7c051
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 18 08:37:42 2021 -0400

    c++: ignore explicit dguides during NTTP CTAD [PR101883]
    
    Since (template) argument passing is a copy-initialization context,
    we mustn't consider explicit deduction guides when deducing a CTAD
    placeholder type of an NTTP.
    
            PR c++/101883
    
    gcc/cp/ChangeLog:
    
            * pt.c (convert_template_argument): Pass LOOKUP_IMPLICIT to
            do_auto_deduction.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/nontype-class49.C: New test.
    
    (cherry picked from commit a6b3db3e8625a3cba1240f0b5e1a29bd6c68b8ca)
Comment 3 Patrick Palka 2021-10-06 14:16:10 UTC
Fixed for GCC 11.3 and 12.