【发布时间】:2015-07-29 21:20:16
【问题描述】:
所以在最新的 Visual Studio 2015 中,以下代码似乎不再起作用:
template<class F>
struct wrapper
{
constexpr wrapper()
{}
};
template<typename T>
constexpr typename std::remove_reference<T>::type *addr(T&& t)
{
return &t;
}
template<class F>
constexpr wrapper<F> wrap(F*)
{
return wrapper<F>();
}
const constexpr auto add_one = wrap(true ? nullptr : addr([](int x)
{
return x + 1;
}));
Visual Studio 报告回illegal initialization of 'constexpr' entity with a non-constant expression。这曾经在候选版本中工作,但最新版本似乎不再工作(我正在使用版本14.0.23107.0)。这应该有效(它在 clang 和 gcc 中都有效)。
很遗憾,Microsoft 不允许我报告错误。那么有人知道解决方法吗?
【问题讨论】:
-
问题不完全是你所说的。将
true ? nullptr : addr(...)更改为true ? (void *) 0 : addr(...)并被接受,即使它使用 lambda。 (我知道这会阻止add_one拥有您想要的类型,我不建议将其作为替代品。) -
如果您想报告错误,请尝试connect.microsoft.com/VisualStudio(哦,对了,它告诉我“您无权提交此连接的反馈。”)
标签: c++ visual-studio c++11 constexpr