2
class Test1
{
public:
    Test1(int){}
};

class Test2Base
{
public:
    Test2Base(int){}
};

class Test2: public Test2Base
{
    using Test2Base::Test2Base; // c++11 constructor inheritence
private:
    Test1 t1{1};
};

Test2 t(1);

The above code compiles fine on clang 3.8. On GCC 5.4.0 and 6.1.0 it fails to compile:

$ g++ -fsyntax-only -std=c++14 main.cpp 
main.cpp:20:10: error: use of deleted function ‘Test2::Test2(int)’
 Test2 t(1);
          ^
main.cpp:15:19: note: ‘Test2::Test2(int)’ is implicitly deleted because the default definition would be ill-formed:
  using Test2Base::Test2Base;
                   ^
main.cpp:15:19: error: no matching function for call to ‘Test1::Test1()’
main.cpp:4:2: note: candidate: Test1::Test1(int)
  Test1(int){}
  ^
main.cpp:4:2: note:   candidate expects 1 argument, 0 provided
main.cpp:1:7: note: candidate: constexpr Test1::Test1(const Test1&)
 class Test1
       ^
main.cpp:1:7: note:   candidate expects 1 argument, 0 provided
main.cpp:1:7: note: candidate: constexpr Test1::Test1(Test1&&)
main.cpp:1:7: note:   candidate expects 1 argument, 0 provided

It looks like a bug in GCC to me, but maybe this code is incorrect for some reason?

user697683
  • 1,423
  • 13
  • 24

0 Answers0