This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/10187: string literal converted to non-const `char[]' when used as argument to function template
- From: bsamwel at xs4all dot nl
- To: gcc-gnats at gcc dot gnu dot org
- Cc: jtv at xs4all dot nl, bsamwel at xs4all dot nl
- Date: 21 Mar 2003 17:47:44 -0000
- Subject: c++/10187: string literal converted to non-const `char[]' when used as argument to function template
- Reply-to: bsamwel at xs4all dot nl
>Number: 10187
>Category: c++
>Synopsis: string literal converted to non-const `char[]' when used as argument to function template
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Mar 21 17:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Bart Samwel
>Release: 3.2.3
>Organization:
>Environment:
Debian unstable, build of 10 feb 2003
>Description:
The following code:
template<typename T>
int foo(const T& x);
template<>
int foo(const char* const& x)
{
}
template<>
int foo(char* const& x)
{
}
int main()
{
foo("bar");
return 0;
}
Gives the following output:
> g++ test.cc
/tmp/cc8rMEFw.o(.text+0x25): In function `main':
: undefined reference to `int foo<char[4]>(char[4] const&)'
collect2: ld returned 1 exit status
This means that, although the string constant should be of type const char* and should resolve to call the first specialization of foo, it in fact doesn't do this at all, it resolves to foo<char[4]> which means that the literal is seen as being of a non-constant type as well! In addition, it is not possible to specialize foo for T=char[] or T=char[4] because of the presence of the reference in the original definition of foo.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: