[英]Visual C++ 14 CTP3: c++11 inheriting constructor bug?
The following code snippet builds perfectly fine under Clang 3.4/3.5 (Xcode 5/6), but throws out the error under Visual C++ 14 CTP3: 以下代码片段在Clang 3.4 / 3.5(Xcode 5/6)下构建完全正常,但在Visual C ++ 14 CTP3下抛出错误:
1>------ Build started: Project: InheritingConstructor, Configuration:
1> ------ Build build:Project:InheritingConstructor,Configuration:
Debug Win32 ------ 1> inheritingconstructor.cpp(60): error C2661:Debug Win32 ------ 1> inheritingconstructor.cpp(60):错误C2661:
'D::D': no overloaded function takes 2 arguments'D :: D':没有重载函数需要2个参数
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ====================构建:0成功,1失败,0最新,0跳过==========
The code does stress the compiler a bit by attempting to inherit a template constructor from the base class, maybe that's where Visual C++ fails again in the competition? 代码通过尝试从基类继承模板构造函数来强调编译器,也许这就是Visual C ++在竞争中再次失败的地方? Or I am hitting some grey area thus undefined behavior in the standard?
或者我在标准中遇到一些灰色区域因此未定义的行为?
#include "stdafx.h" // comment out this line for Xcode build
#include <iostream>
#include <type_traits>
template <typename X>
struct B
{
int i;
B(int i_) : i(i_) {}
template < typename T, typename = typename std::enable_if<
std::is_same<T, X>::value >::type >
B(const T*, const T*) : i(0) {}
};
struct D : B<D>
{
using B<D>::B; // inherit constructors from B
};
int main(int argc, const char * argv[]) {
// insert code here...
D d((D*)nullptr, (D*)nullptr);
std::cout << "Hello, World!\n";
return 0;
}
There's nothing wrong with your code from a standard compliance perspective. 从标准合规性角度来看,您的代码没有任何问题。
Inheriting constructors are not implemented in VC++2013 LINK . VC ++ 2013 LINK中未实现继承构造函数 。
However, as this LINK suggests this kind of functionality is implemented since VC++2014 CTP 1. 但是,正如这个LINK建议这样的功能是从VC ++ 2014 CTP 1开始实现的。
Digging up a little bit, I found that exactly the same bug with the same example was reported this morning LINK . 稍微挖掘一下,我发现今天早上LINK报道了同一个例子的完全相同的错误 。
Bottom line: This is a VC++2014 bug that it has already been reported. 结论:这是一个已经报告过的VC ++ 2014漏洞。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.