* string literals in struct initializers with C++
@ 2002-10-15 11:44 J.T. Conklin
2002-10-15 13:04 ` Michael Ritzert
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: J.T. Conklin @ 2002-10-15 11:44 UTC (permalink / raw)
To: gcc
In the process of moving from the gcc-3_2-branch to the CVS head, I found
code with string literals in struct initializers no longer compiles using
g++. I'm not sure whether this is just a tightening of the parser or a
bug.
The following code:
struct foo {
char x[20];
int y;
int z;
};
struct foo foos[] = {
{ "foo", 0, 2 },
{ "bar", 1, 3 }
};
Now results in:
foo.cc:10: error: invalid conversion from `const char*' to `char'
foo.cc:10: error: invalid conversion from `const char*' to `char'
When it used to compile with older versions of g++. It continues to
compile with gcc.
--jtc
--
J.T. Conklin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: string literals in struct initializers with C++
2002-10-15 11:44 string literals in struct initializers with C++ J.T. Conklin
@ 2002-10-15 13:04 ` Michael Ritzert
2002-10-15 13:10 ` J.T. Conklin
2002-10-15 15:16 ` Mark Mitchell
2 siblings, 0 replies; 4+ messages in thread
From: Michael Ritzert @ 2002-10-15 13:04 UTC (permalink / raw)
To: jtc; +Cc: gcc
On Tuesday 15 October 2002 19:58, J.T. Conklin wrote:
> The following code:
>
> struct foo {
> char x[20];
> int y;
> int z;
> };
>
> struct foo foos[] = {
> { "foo", 0, 2 },
> { "bar", 1, 3 }
> };
>
> Now results in:
> foo.cc:10: error: invalid conversion from `const char*' to `char'
> foo.cc:10: error: invalid conversion from `const char*' to `char'
I hit the same error message during my daily build of STLport. The simplified
code looks like this:
-bash-2.05b$ gcc -v
Reading specs from
/home/ritzert/gcc-HEAD/install/lib/gcc-lib/i386-unknown-freebsd4.5/3.3/specs
Configured with: /home/ritzert/gcc-HEAD/gcc/configure --enable-threads=posix
--prefix=/home/ritzert/gcc-HEAD/install
Thread model: posix
gcc version 3.3 20021014 (experimental)
-bash-2.05b$ cat x.cpp
const char x[][2] = { "Hello", "world" };
-bash-2.05b$ gcc -c x.cpp
x.cpp:1: error: invalid conversion from `const char*' to `char'
x.cpp:1: error: invalid conversion from `const char*' to `char'
It compiled fine just a week ago. (Sorry, I can't be more precise; first there
was the anoncvs update problem, then my build machine went down...).
Michael
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: string literals in struct initializers with C++
2002-10-15 11:44 string literals in struct initializers with C++ J.T. Conklin
2002-10-15 13:04 ` Michael Ritzert
@ 2002-10-15 13:10 ` J.T. Conklin
2002-10-15 15:16 ` Mark Mitchell
2 siblings, 0 replies; 4+ messages in thread
From: J.T. Conklin @ 2002-10-15 13:10 UTC (permalink / raw)
To: gcc
jtc@acorntoolworks.com (J.T. Conklin) writes:
> In the process of moving from the gcc-3_2-branch to the CVS head, I found
> code with string literals in struct initializers no longer compiles using
> g++. I'm not sure whether this is just a tightening of the parser or a
> bug.
FWIW, The same or similar problem appears to effect the following code:
#include <string>
struct bar {
std::string s;
int y;
int z;
};
bar bar_array[] = {
{ "abc", 1, 2 },
{ "def", 2, 4 },
{ "ghi", 3, 6 },
{ "klm", 4, 8 }
};
Which results in:
bar.cc:14: error: conversion from `const char[4]' to non-scalar type
`bar' requested
bar.cc:14: error: conversion from `const char[4]' to non-scalar type
`bar' requested
bar.cc:14: error: conversion from `const char[4]' to non-scalar type
`bar' requested
bar.cc:14: error: conversion from `const char[4]' to non-scalar type
`bar' requested
Unlike the privious example, this one can't be worked around with an
extra layer of {}'s.
And since I neglected to mention it before, this is a g++ from the CVS head,
on QNX 6.2 (the changes I submitted for QNX in August with slight tweaks as
suggested by Zack and as necessary to to adapt to the CVS head.
--jtc
--
J.T. Conklin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: string literals in struct initializers with C++
2002-10-15 11:44 string literals in struct initializers with C++ J.T. Conklin
2002-10-15 13:04 ` Michael Ritzert
2002-10-15 13:10 ` J.T. Conklin
@ 2002-10-15 15:16 ` Mark Mitchell
2 siblings, 0 replies; 4+ messages in thread
From: Mark Mitchell @ 2002-10-15 15:16 UTC (permalink / raw)
To: jtc, gcc
--On Tuesday, October 15, 2002 10:58:05 AM -0700 "J.T. Conklin"
<jtc@acorntoolworks.com> wrote:
> In the process of moving from the gcc-3_2-branch to the CVS head, I found
> code with string literals in struct initializers no longer compiles using
> g++. I'm not sure whether this is just a tightening of the parser or a
> bug.
>
A bug; I'm testing a fix as we speak.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-10-15 21:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 11:44 string literals in struct initializers with C++ J.T. Conklin
2002-10-15 13:04 ` Michael Ritzert
2002-10-15 13:10 ` J.T. Conklin
2002-10-15 15:16 ` Mark Mitchell
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).