【发布时间】:2018-05-14 11:10:53
【问题描述】:
为什么这不能在 Visual Studio C++ 中编译?我正在使用 Visual Studio 2017 15.7.1。它在 clang 和 g++ 中编译:
#include <utility>
#include <vector>
struct Foo {
Foo(int x) {}
Foo(Foo const& b) {}
};
struct Bar {
template <class... Args>
Bar(Args&&... args)
: foo(std::forward<Args>(args)...) {}
Foo foo;
};
void test() {
std::vector<Bar> v;
v.emplace_back(123);
}
错误是error C2664: 'Foo::Foo(const Foo &)': cannot convert argument 1 from 'Bar' to 'int'
编辑:我在这里提交了这个问题:https://developercommunity.visualstudio.com/content/problem/252470/perfect-forwarding-compiler-bug.html
【问题讨论】:
-
它看起来像一个编译器错误,你应该向 MS 报告这个
-
已通过 MSVS 15.6.6 和工具集 v141 确认。但它使用工具集 v140 和 v140_xp 编译
-
这是一个非常糟糕的错误
标签: c++ compiler-errors visual-studio-2017