public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10187: string literal converted to non-const `char[]' when used as argument to function template
@ 2003-03-21 23:24 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-03-21 23:24 UTC (permalink / raw)
  To: bsamwel, gcc-bugs, gcc-prs, jtv, bsamwel, nobody

Synopsis: string literal converted to non-const `char[]' when used as argument to function template

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Fri Mar 21 23:24:53 2003
State-Changed-Why:
    By 2.13.4.1, 
      An ordinary string literal has type "array of n const
      char"  and  static storage duration (_basic.stc_), where n is the size
      of the string as defined below, and  is  initialized  with  the  given
      characters.
    
    To get the effect you want, declare a function
      template <int N>
      int foo (const char (&x)[N])
      {}
    

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10187


^ permalink raw reply	[flat|nested] 2+ messages in thread
* c++/10187: string literal converted to non-const `char[]' when used as argument to function template
@ 2003-03-21 17:56 bsamwel
  0 siblings, 0 replies; 2+ messages in thread
From: bsamwel @ 2003-03-21 17:56 UTC (permalink / raw)
  To: gcc-gnats; +Cc: jtv, bsamwel


>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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-03-21 23:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-21 23:24 c++/10187: string literal converted to non-const `char[]' when used as argument to function template bangerth
  -- strict thread matches above, loose matches on Subject: below --
2003-03-21 17:56 bsamwel

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).