Consider the code:
class A {
public:
        virtual void foo() = 0;
};

class B : public A {
public:
        virtual void foo() {}
};

int main()
{
        const A &a = B(); // <-- here
        return 0;
}


in g++-4.0, as it comes pre-installed on Mac 10.4, I get the error:
$ g++ -c g++4-bug.cc
g++4-bug.cc: In function `int main()':
g++4-bug.cc:15: error: cannot allocate an object of abstract type 'A'
g++4-bug.cc:3: note:   because the following virtual functions are pure within 
'A':
g++4-bug.cc:5: note:  virtual void A::foo()

However, this code compiles without complaint on the g++-3.4 that comes
preinstalled on this system.  I don't know whether this has been fixed since
gcc-4.0, but it doesn't seem to me like there's any reason for gcc to reject
this code.

Thanks,
Michael

-- 
           Summary: Compiler will not create references of abstract types
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vircum at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-apple-darwin8.1.0
  GCC host triplet: powerpc-apple-darwin8.1.0
GCC target triplet: powerpc-apple-darwin8.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21746

Reply via email to