public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: bsamwel@xs4all.nl To: gcc-gnats@gcc.gnu.org Cc: jtv@xs4all.nl, bsamwel@xs4all.nl Subject: c++/10187: string literal converted to non-const `char[]' when used as argument to function template Date: Fri, 21 Mar 2003 17:56:00 -0000 [thread overview] Message-ID: <20030321174744.763.qmail@sources.redhat.com> (raw) >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:
next reply other threads:[~2003-03-21 17:56 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-03-21 17:56 bsamwel [this message] 2003-03-21 23:24 bangerth
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20030321174744.763.qmail@sources.redhat.com \ --to=bsamwel@xs4all.nl \ --cc=gcc-gnats@gcc.gnu.org \ --cc=jtv@xs4all.nl \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).