bug report

Cristi Vlasceanu CristiV@netzip.com
Wed Dec 22 11:31:00 GMT 1999


// This code demonstrates a bug in the following compilers:
//
// MSVC++ 6.0 (sp3)
// Code Warrior 5.0
// egcs 2.91.60 (system: Caldera Open Linux 2.1, command line: g++ main.cpp)
// Comeau 4.2.42 (online test drive)

#include <iostream>
using namespace std;


class A
{
public:
    A() {}
    /* explicit */ A(int) {}

    virtual void Func() const = 0;
};

void Fubar(const A& a)
{
    a.Func();
}

int main()
{
    // error: cannot instantiate abstract class 
    // A a;

    // error: cannot instantiate abstract class 
    // A a(42);
    try
    {
        // *****************************************
        // implicit conversion to abstract class A,
        // should not compile but it does, when using:
        // MSVC++ 6.0 (sp3)
        // Code Warrior 5.0
        // egcs 2.91.60
        // Comeau 4.2.42

        // The error is promptly detected by  Borland
        // C++ Builder 4.0
        Fubar(42); 

        // error: cannot instantiate abstract class
        // throw A();

        // compiles fine under MSVC 6.0 SP3, but
        // shouldn't 
        // throw A(0);
    }
    catch (A& a)
    {
        a.Func();
    }
    return 0;
}


Cristian Vlasceanu,
Software Engineer, Netzip Inc. 


More information about the Gcc-bugs mailing list