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: Typedef Structure Inheritance


> Hi.  I am getting an error when compiling some code and I was able to 
> distill it down to this code
> 
> typedef struct {
>    virtual const char *blah() {
>      return "Heya::blah";
>    }
> } Heya;
> 
> struct Grok : public Heya {
>    virtual const char *blah() {
>      return "Grok::blah";
>    }
> };
> 
> int main() {
>    Grok *g = new Grok();
>    delete g;
>    return 0;
> }
> 
> When running gcc 3.2.1 (command line "g++ -c broken.cc") with the 
> latest gcc-3.2 packege in Debian Unstable I get the following error...
> borken.cc:10: redefinition of `const char _ZTS4Heya[6]'
> broken.cc:10: `const char _ZTS4Heya[6]' previously defined here

This is a bug, and I've confirmed it in the official gcc 3.2.1.
I created a PR for it.

> But when running it with gcc-2.95.4 (again, the latest package in 
> Debian Unstable) the file compiles without error.

The GCC project never released anything named gcc-2.95.4.

> Is this a bug in 
> gcc? or is the above code not ISO C++ compilant and that is why gcc3.2 
> is bombing on it?  It is kinda a wierd construction and I am not sure 
> that it is even valid C++ code.  One interesting thing to note, remove 
> the "new" and "delete" lines from the main function and the error is 
> not generated, even with gcc3.2

It's a bug, though easy to work around; try

struct Heya {
    virtual const char *blah() {
      return "Heya::blah";
    }
};


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