constexpr错误;VS2017 C++编译器回归?

9
刚刚安装了声称比2015版(基本版本)具有更出色C++14支持的VS2017。在我的一个使用了constexpr的项目上试用了一下,发现似乎出现了一些退化。
以下是代码:
struct s
{
    size_t i;
    constexpr s(nullptr_t) noexcept : i(0) {}
};
static_assert(s(nullptr).i == 0, "!!");

在VS2015和Clang上编译没有问题,但在VS2017上出现了新的错误:

error C2131: expression did not evaluate to a constant
note: failure was caused by unevaluable pointer value
note: while evaluating 's::s(&s{(null)})'

这段代码看起来没问题,对吧?constexpr 是否应该与 nullptr 有问题?
我惊讶于这么基础的回归错误居然出现了,我怀疑我的代码可能有问题...


即使只是 constexpr s x{nullptr}; 也会出现无意义的错误 (note: while evaluating 's::s(&x)' – 什么鬼?);显然是个 bug。 - ildjarn
让我惊讶的是,一个如此简单和琐碎的东西竟然可能会被编译器的单元测试所忽略... - Manu Evans
另一个代码片段,在最简单的字符串拆分例程中引发相同错误:while (*tmp) { if (a_delim == *tmp) { count++; last_comma = tmp; } tmp++; } - ibanjo
@ibanjo:你发布的代码与“同样的错误”有什么关联? - AnT stands with Russia
@AnT 我检查了一下,实际上误解了这篇帖子。抱歉。 - ibanjo
显示剩余2条评论
1个回答

1

使用std::nullptr_t作为constexpr构造函数会导致"error C2131: expression did not evaluate to a constant"错误。

这个问题在Visual Studio 2017版本15.1中被报告为一个bug。
之前由OP(?)报告了另一个问题的变体。

这个问题已经在Visual Studio 2017版本15.6 Preview 1中得到修复。


想把这个问题从未回答的问题列表中移除。 - P.W

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接