https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83796

            Bug ID: 83796
           Summary: Abstract classes allowed to be instantiated when
                    initialised as default parameter to function or
                    constructor
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johnsonmichaelgraham at gmail dot com
  Target Milestone: ---

Test Case:

class MyAbstractClass
{
public:
    virtual int foo() const = 0;
};

class TestClass
{
public:
    TestClass(const MyAbstractClass& m = {}) // should generate compiler error
        : value_(m.foo()) {}

    int value_;
};

int TestFunction(const MyAbstractClass& m = {}) // should generate compiler
error
{
    return m.foo();
}

int main(int argc, char *argv[])
{
    TestClass testInstance;

    std::cout << testInstance.value_ << std::endl;

    std::cout << TestFunction() << std::endl;

    return 0;
}

// Compiles OK

runtime output:

pure virtual method called
terminate called without an active exception

Reply via email to