This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: string literals in struct initializers with C++
- From: jtc at acorntoolworks dot com (J.T. Conklin)
- To: gcc at gcc dot gnu dot org
- Date: 15 Oct 2002 12:02:46 -0700
- Subject: Re: string literals in struct initializers with C++
- References: <87vg43bn4i.fsf@orac.acorntoolworks.com>
- Reply-to: jtc at acorntoolworks dot com
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