This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/2988: Incorrect error on assignment of const char[] to char *
- To: rodrigc at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- Subject: Re: c++/2988: Incorrect error on assignment of const char[] to char *
- From: Richard Smith <ros at tao-group dot com>
- Date: Fri, 15 Jun 2001 11:26:18 +0100
- Organization: Tao Systems
- References: <20010615021003.8805.qmail@sourceware.cygnus.com>
On Fri, 15 Jun 2001, rodrigc@gcc.gnu.org wrote:
> Synopsis: Incorrect error on assignment of const char[] to char *
>
> State-Changed-From-To: open->closed
> State-Changed-By: rodrigc
> State-Changed-When: Thu Jun 14 19:10:03 2001
> State-Changed-Why:
> Your test case compiles without error and without warning
> with: gcc version 3.0 20010614 (prerelease)
>
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2988&database=gcc
Thanks for looking at this. I'm afraid I attached an incorrect demo (as I
had looked for workarounds and then forgot ...) and was unable to update the PR
itself. As I feared, my note to gcc-bugs may have been insufficient.
The demo should be changed such that the line
args[1] = (flags==0) ? (char *)"-n" : (char *)"-p";
becoems
args[1] = (flags==0) ? "-n" : "-p";
I tried this on 3.0 and did get the problem. However, it is possible that gcc
_is_ correct in its behaviour: this is a comment from one of my colleagues:
> The code that fails looks like this:
>
> char *args; int flags;
> args = (flags == 0) ? "-n" : "-p";
>
> From a haphazard reading of an old draft of the C++ standard, I think
> GCC is probably right to reject this. Your C++ book is correct in
> saying that "a string literal can be assigned to char *", but the thing
> you're trying to assign here is not a string literal, it's the result of
> some expression which happens to have the same type that a string
> literal has.
So the question is whether a conditional expression returning a static char *
should be accepted for assignment to a char * in the same way that an actual
static char * should be (and is).
Thanks!
--
Regards,
Richard Smith