9

这是一个 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>path\to\filename(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

NB MSVC 2015 对继承构造函数的支持是该版本的新增功能

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

错误报告在这里

4

1 回答 1

6

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

于 2015-07-25T21:18:28.030 回答