这段代码是否正确?它在clang上编译好并且在GCC上失败

时间:2016-08-04 16:39:05

标签: c++ c++11 gcc

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);

上面的代码在clang 3.8上编译得很好。在GCC 5.4.0和6.1.0上,它无法编译:

$ 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

对我来说,它看起来像GCC中的一个错误,但是由于某种原因,这段代码可能不正确?

0 个答案:

没有答案