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

            Bug ID: 115665
           Summary: gcc complains about bad CTAD that actually does not
                    exist in template derived class with default argument
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rush102333 at gmail dot com
  Target Milestone: ---

The following code triggers a compilation failure in gcc-13.2:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct B{
    B(int){}
};
template <typename=int>struct D:B {
  using B::B;
  /*this is OK*/
  //D(int m):B(m){}
};
D d(0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The compiler outputs the following error message that is somewhat puzzling:


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:8:6: error: class template argument deduction failed:
    8 | D d(0);
      |      ^
<source>:8:6: error: no matching function for call to 'D(int)'
<source>:4:31: note: candidate: 'template<class> D()-> D<
<template-parameter-1-1> >'
    4 | template <typename=int>struct D:B {
      |                               ^
<source>:4:31: note:   candidate expects 0 arguments, 1 provided
<source>:4:31: note: candidate: 'template<class> D(D< <template-parameter-1-1>
>)-> D< <template-parameter-1-1> >'
<source>:4:31: note:   template argument deduction/substitution failed:
<source>:8:6: note:   mismatched types 'D< <template-parameter-1-1> >' and
'int'
    8 | D d(0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It seems that there is no need for a class template argument deduction in the
instantiation of "D d(0)", because class "D" already has a default template
argument value. It's also worth noting that when we replace the expression
"using B::B;" in line 5 with a semantic equivalence form "D(int m):B(m){}" in
line 7, the code does compile. 

Clang also accepts this code. That makes us believe that there may be a bug in
GCC.

Please check https://godbolt.org/z/TMT9Yhqz1.

Reply via email to