This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: string literals in struct initializers with C++


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]