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

Sam Huang <samestimable2016 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samestimable2016 at gmail dot 
com

--- Comment #2 from Sam Huang <samestimable2016 at gmail dot com> ---
I was going to file the same bug but with a different and much simpler
scenario. The compiler fails to deduce the parameter when you pass a non-type
template parameter to another template.

Consider the following scenario (tested on compiler explorer using GCC 9.1,
9.2, 9.3, 10.1, 10.2 with options -std=c++2a -O3):

>>>>>>>>>>>>>>>>>>>>>>>>>>>

#include <array>
#include <cstddef>

template<std::size_t N>
struct constexpr_string
{
    std::array<char, N> _data;

public:
    constexpr constexpr_string(const char (&data)[N])
    {
        std::copy(std::begin(data), std::end(data), _data.data());
    }
};

template<constexpr_string String>
struct foo
{};

template<constexpr_string String>
struct bar
{
    using type = foo<String>; // <-- Fails to compile on this line
};

int main()
{}

>>>>>>>>>>>>>>>>>>>>>>>>>>>

The diagnostic produced by the compiler is:
"
<source>:23:28: error: class template argument deduction failed:

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:23:28: error: no matching function for call to
'constexpr_string(constexpr_string<...auto...>)'

<source>:10:15: note: candidate: 'template<long unsigned int N>
constexpr_string(const char (&)[N])-> constexpr_string<N>'

   10 |     constexpr constexpr_string(const char (&data)[N])

      |               ^~~~~~~~~~~~~~~~

<source>:10:15: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'const char [N]' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:5:8: note: candidate: 'template<long unsigned int N>
constexpr_string(constexpr_string<N>)-> constexpr_string<N>'

    5 | struct constexpr_string

      |        ^~~~~~~~~~~~~~~~

<source>:5:8: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'constexpr_string<N>' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

ASM generation compiler returned: 1

<source>:23:28: error: class template argument deduction failed:

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:23:28: error: no matching function for call to
'constexpr_string(constexpr_string<...auto...>)'

<source>:10:15: note: candidate: 'template<long unsigned int N>
constexpr_string(const char (&)[N])-> constexpr_string<N>'

   10 |     constexpr constexpr_string(const char (&data)[N])

      |               ^~~~~~~~~~~~~~~~

<source>:10:15: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'const char [N]' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

<source>:5:8: note: candidate: 'template<long unsigned int N>
constexpr_string(constexpr_string<N>)-> constexpr_string<N>'

    5 | struct constexpr_string

      |        ^~~~~~~~~~~~~~~~

<source>:5:8: note:   template argument deduction/substitution failed:

<source>:23:28: note:   mismatched types 'constexpr_string<N>' and
'constexpr_string<...auto...>'

   23 |     using type = foo<String>; // <-- Fails to compile on this line

      |                            ^

Execution build compiler returned: 1
"

Reply via email to