https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94619
Sam Huang changed:
What|Removed |Added
CC||samestimable2016 at gmail dot
com
--- Comment #2 from Sam Huang ---
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
#include
template
struct constexpr_string
{
std::array _data;
public:
constexpr constexpr_string(const char ()[N])
{
std::copy(std::begin(data), std::end(data), _data.data());
}
};
template
struct foo
{};
template
struct bar
{
using type = foo; // <-- Fails to compile on this line
};
int main()
{}
>>>
The diagnostic produced by the compiler is:
"
:23:28: error: class template argument deduction failed:
23 | using type = foo; // <-- Fails to compile on this line
|^
:23:28: error: no matching function for call to
'constexpr_string(constexpr_string<...auto...>)'
:10:15: note: candidate: 'template
constexpr_string(const char (&)[N])-> constexpr_string'
10 | constexpr constexpr_string(const char ()[N])
| ^~~~
:10:15: note: template argument deduction/substitution failed:
:23:28: note: mismatched types 'const char [N]' and
'constexpr_string<...auto...>'
23 | using type = foo; // <-- Fails to compile on this line
|^
:5:8: note: candidate: 'template
constexpr_string(constexpr_string)-> constexpr_string'
5 | struct constexpr_string
|^~~~
:5:8: note: template argument deduction/substitution failed:
:23:28: note: mismatched types 'constexpr_string' and
'constexpr_string<...auto...>'
23 | using type = foo; // <-- Fails to compile on this line
|^
ASM generation compiler returned: 1
:23:28: error: class template argument deduction failed:
23 | using type = foo; // <-- Fails to compile on this line
|^
:23:28: error: no matching function for call to
'constexpr_string(constexpr_string<...auto...>)'
:10:15: note: candidate: 'template
constexpr_string(const char (&)[N])-> constexpr_string'
10 | constexpr constexpr_string(const char ()[N])
| ^~~~
:10:15: note: template argument deduction/substitution failed:
:23:28: note: mismatched types 'const char [N]' and
'constexpr_string<...auto...>'
23 | using type = foo; // <-- Fails to compile on this line
|^
:5:8: note: candidate: 'template
constexpr_string(constexpr_string)-> constexpr_string'
5 | struct constexpr_string
|^~~~
:5:8: note: template argument deduction/substitution failed:
:23:28: note: mismatched types 'constexpr_string' and
'constexpr_string<...auto...>'
23 | using type = foo; // <-- Fails to compile on this line
|^
Execution build compiler returned: 1
"