[Bug c++/83796] New: Abstract classes allowed to be instantiated when initialised as default parameter to function or constructor

2018-01-11 Thread johnsonmichaelgraham at gmail dot com
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

[Bug c++/83796] Abstract classes allowed to be instantiated when initialised as default parameter to function or constructor

2018-01-12 Thread johnsonmichaelgraham at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83796

Michael Johnson  changed:

   What|Removed |Added

Version|5.4.0   |7.2.0

--- Comment #1 from Michael Johnson  ---
Correctly won't compile on MSVC and Clang, erroneously compiles from gcc 4.7.3
onwards

Godbolt: https://godbolt.org/g/EuR2cy

I think may be caused by change:
https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/cp/call.c?r1=194820&r2=194819&pathrev=194820&diff_format=f

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