使用继承构造函数时,VS2015内部编译器错误

VS2015 Internal Compiler Error when using inheriting constructors

本文关键字:VS2015 内部 编译器 错误 继承 构造函数      更新时间:2023-10-16

下面是一个10行c++ 11程序,从我正在编写的程序大为简化:

template <typename T> class Base { public:
    template <typename S> Base(S x) {}
};
template <typename T> class Child : public Base<T> { public:
    using Base<T>::Base;
};
template <> class Child<int> : public Base<int> { public:
    using Base<int>::Base;
};
int main()
{
    Child<int> child(8.0f);
}

MSVC 2015输出:

1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>  filename.cpp
1>pathtofilename(10): fatal error C1001: An internal error has occurred in the compiler.
1>  (compiler file 'msc1.cpp', line 1393)
1>   To work around this problem, try simplifying or changing the program near the locations listed above.
1>  Please choose the Technical Support command on the Visual C++
1>   Help menu, or open the Technical Support help file for more information

注意:MSVC 2015在该版本中新增了对继承构造函数的支持。

我已经提交了一个bug报告,因为至少编译器不会崩溃。但是,我可以确认这是正确的c++用法/解决方案吗?

这里有Bug报告

正如评论中提到的,这似乎是一个MSVC问题。用Clang和-std=c++11快速编译,没有问题。