constexpr错误; VS2017 C ++编译器回归? [英] constexpr errors; VS2017 C++ compiler regression?

查看:311
本文介绍了constexpr错误; VS2017 C ++编译器回归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅安装了VS2017,该版本自2015年以来声称具有更高的C ++ 14支持(基本)。
试一下我的一个使用 constexpr 的项目,并注意到其中似乎存在一些回归。

Just installed VS2017, which claims to have superior C++14 support since 2015 (which was rudimentary). Gave it a spin on one of my projects which uses constexpr, and noticed what appear to be some regressions.

此代码:

struct s
{
    size_t i;
    constexpr s(nullptr_t) noexcept : i(0) {}
};
static_assert(s(nullptr).i == 0, "!!");

在VS2015和Clang上没有问题,但是在VS2017中出现新错误:

Compiles no problem on VS2015 and Clang, but I get a new error in 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 有问题?

我很惊讶对此进行回归基本可能会出现,我怀疑我的代码肯定有问题...

This code looks fine right? Is constexpr meant to have a problem with nullptr?
I'm astonished a regression this basic could appear, I suspect there must be something wrong with my code...

推荐答案


constexpr构造函数(std :: nullptr_t)导致错误C2131:表达式未求值为常量

constexpr constructor(std::nullptr_t) causes "error C2131: expression did not evaluate to a constant"

此问题是已报告为Visual Studio 2017中的错误版本15.1。

还有另一个问题由OP(?)先前报告。

This issue was reported as a bug in Visual Studio 2017 version 15.1.
There was a variation of another issue reported earlier by the OP (?).

此问题已在以下版本中修复:Visual Studio 2017版本15.6预览版1

This was fixed in: Visual Studio 2017 version 15.6 Preview 1

这篇关于constexpr错误; VS2017 C ++编译器回归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆