public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94619] New: String literals as non-type template parameter fails to compile with partial specialization of calling function
@ 2020-04-16 14:20 pacoarjonilla at yahoo dot es
2020-04-16 16:07 ` [Bug c++/94619] " daniel.kruegler at googlemail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pacoarjonilla at yahoo dot es @ 2020-04-16 14:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94619
Bug ID: 94619
Summary: String literals as non-type template parameter fails
to compile with partial specialization of calling
function
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pacoarjonilla at yahoo dot es
Target Milestone: ---
I'm not sure if this is correct C++, but the compiler seems to be unable to
deduce the template parameter of fu when it is a non-type kind.
If the code is not correct, this error blocks fu from being overloaded by more
specific templates :(
The diagnostic
"
mismatched types ‘A<length>’ and ‘A<...auto...>’
"
is suspicious of a bug in GCC
>>>>>>>>>>>>>>>>>>>>>>>>>>>
template <unsigned length> struct A {
char str [length];
constexpr A(char const (&s) [length]) {
for (int i = 0; i < length; ++i)
str[i] = s[i];
}
};
template <A a> struct B {
void bar() const {
return a.str;
}
};
//template <typename T> void fu (T const& t) // Compiles successfully
template <A a> void fu (B<a> const& t) // Does not compile
//template <unsigned l> void fu (B<A<l>> const& t) // Does not compile either
{
t.bar();
}
void test() {
B<":/"> m;
fu(m);
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>
gcc10 --std=c++20 code.cc -c
meta.cc:17:37: error: class template argument deduction failed:
17 | template <A a> void fu (B<a> const& t) // Does not compile
| ^
meta.cc:17:37: error: no matching function for call to ‘A(A<...auto...>)’
meta.cc:4:15: note: candidate: ‘template<unsigned int length> A(const char
(&)[length])-> A<length>’
4 | constexpr A(char const (&s) [length]) {
| ^
meta.cc:4:15: note: template argument deduction/substitution failed:
meta.cc:17:37: note: mismatched types ‘const char [length]’ and
‘A<...auto...>’
17 | template <A a> void fu (B<a> const& t) // Does not compile
| ^
meta.cc:1:35: note: candidate: ‘template<unsigned int length> A(A<length>)->
A<length>’
1 | template <unsigned length> struct A {
| ^
meta.cc:1:35: note: template argument deduction/substitution failed:
meta.cc:17:37: note: mismatched types ‘A<length>’ and ‘A<...auto...>’
17 | template <A a> void fu (B<a> const& t) // Does not compile
| ^
meta.cc: In function ‘void fu(const int&)’:
meta.cc:20:9: error: request for member ‘bar’ in ‘t’, which is of non-class
type ‘const int’
20 | t.bar();
| ^~~
meta.cc: In function ‘void test()’:
meta.cc:25:9: error: no matching function for call to ‘fu(B<A<3>{":/"}>&)’
25 | fu(m);
| ^
meta.cc:17:30: note: candidate: ‘template<A<...auto...> a> void fu(const int&)’
17 | template <A a> void fu (B<a> const& t) // Does not compile
| ^~
meta.cc:17:30: note: template argument deduction/substitution failed:
meta.cc:25:9: note: couldn’t deduce template parameter ‘a’
25 | fu(m);
| ^
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/94619] String literals as non-type template parameter fails to compile with partial specialization of calling function
2020-04-16 14:20 [Bug c++/94619] New: String literals as non-type template parameter fails to compile with partial specialization of calling function pacoarjonilla at yahoo dot es
@ 2020-04-16 16:07 ` daniel.kruegler at googlemail dot com
2020-08-25 14:34 ` samestimable2016 at gmail dot com
2021-08-05 4:46 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2020-04-16 16:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94619
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler@googlemail.
| |com
--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
The non-void return expression in the void bar function makes the example
ill-formed regardless of the other problem, so let's fix that first:
>>>>>>>>>>>>>>
template <unsigned length> struct A {
char str [length];
constexpr A(char const (&s) [length]) {
for (unsigned i = 0; i < length; ++i)
str[i] = s[i];
}
};
template <A a> struct B {
auto bar() const {
return a.str;
}
};
//template <typename T> void fu (T const& t) // Compiles successfully
template <A a> void fu (B<a> const& t) // Does not compile
//template <unsigned l> void fu (B<A<l>> const& t) // Does not compile either
{
t.bar();
}
void test() {
B<":/"> m;
fu(m);
}
>>>>>>>>>>>>>>>>>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/94619] String literals as non-type template parameter fails to compile with partial specialization of calling function
2020-04-16 14:20 [Bug c++/94619] New: String literals as non-type template parameter fails to compile with partial specialization of calling function pacoarjonilla at yahoo dot es
2020-04-16 16:07 ` [Bug c++/94619] " daniel.kruegler at googlemail dot com
@ 2020-08-25 14:34 ` samestimable2016 at gmail dot com
2021-08-05 4:46 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: samestimable2016 at gmail dot com @ 2020-08-25 14:34 UTC (permalink / raw)
To: gcc-bugs
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
"
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/94619] String literals as non-type template parameter fails to compile with partial specialization of calling function
2020-04-16 14:20 [Bug c++/94619] New: String literals as non-type template parameter fails to compile with partial specialization of calling function pacoarjonilla at yahoo dot es
2020-04-16 16:07 ` [Bug c++/94619] " daniel.kruegler at googlemail dot com
2020-08-25 14:34 ` samestimable2016 at gmail dot com
@ 2021-08-05 4:46 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-05 4:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94619
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |10.3.0, 11.1.0
Known to fail| |10.2.0
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Seems to be fixed in GCC 10.3.0 and 11+.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-05 4:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16 14:20 [Bug c++/94619] New: String literals as non-type template parameter fails to compile with partial specialization of calling function pacoarjonilla at yahoo dot es
2020-04-16 16:07 ` [Bug c++/94619] " daniel.kruegler at googlemail dot com
2020-08-25 14:34 ` samestimable2016 at gmail dot com
2021-08-05 4:46 ` pinskia at gcc dot gnu.org
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).