This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Compiling GCC With a C++ Compiler (g++)
Geoffrey Keating <geoffk@apple.com> writes:
| On 12/10/2004, at 12:38 AM, Ranjit Mathew wrote:
|
| > Ranjit Mathew wrote:
| >> The definition of tree_string is:
| >>
| >> struct tree_string GTY(())
| >> {
| >> struct tree_common common;
| >> int length;
| >> const char str[1];
| >> };
| >>
| >> If the "const" is removed from above, the compilation
| >> proceeds.
| >
| > The "const char *pointer" -> "const char str[1]" change
| > was done by geoffk as a part of fixing pch/13361.
| >
| > We now want to store the string in the node itself,
| > rather than merely pointing to it.
| >
| > However, I still think that the "const" is
| > misleading/incorrect. In build_string() in tree.c,
| > we cast it to (char *) anyways before memcpy-ing the
| > desired string into it.
| >
| > Would it be wrong to remove it? (And thus re-enable
| > compiling this bit of GCC with a C++ compiler like
| > g++.)
|
| The 'const' is there to indicate that the string should not be changed
| once the STRING_CST is created;
And how do you create it?
| STRING_CSTs may be shared.
Sharing is orthogonal to being marked "const".
|
| Why is C++ complaining about this?
Because, if you mark a data member as const, then you have to
initialize it somehow at object contruction time -- either through
brace-enclosed initializer or real constructors. But, now, you go on
putting it in a union, and that union does not even happen to be the
first member. On the only way you can put a data in that slot is to
assign to it! That does not look like a reasonable construct.
-- Gaby