小编P K*_*mer的帖子

通过接受原始数组引用的 constexpr 构造函数初始化 constexpr 变量时的 MSVC 错误?

使用最新的 GCC 和 Clang 稳定版本时,以下代码可以正常编译。

然而,MSVC 给出了一个错误,即矩阵的初始化未计算为常量。这是 MSVC 错误还是我错过了什么?

实例

<source>(72): error C2131: expression did not evaluate to a constant
<source>(71): note: failure was caused by out of range index 4; allowed range is 0 <= index < 4
Run Code Online (Sandbox Code Playgroud)
#include <cassert>
#include <cstring>
#include <iostream>
#include <utility>
#include <stdexcept>

struct index_t final
{
    constexpr index_t() = default;
    constexpr index_t(const std::size_t r, const std::size_t c) :
        row{ r },
        col{ c }
    {
    }

    std::size_t row{};
    std::size_t col{};
};


template<typename …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors

5
推荐指数
1
解决办法
215
查看次数

标签 统计

c++ ×1

compiler-errors ×1