GCC 和 MSVC 中 consteval 的不同行为(无效)

Different behavior of consteval in GCC and MSVC (not work)

考虑以下代码:

#include <cstdint>
#include <vector>

class ClassT
{
public:
    consteval static size_t GetSize()
    {
        return sizeof(int);
    }

    void Resize()
    {
        _Data.resize(GetSize(), 0);
    }

    std::vector<uint8_t> _Data;
};

int main()
{
    ClassT Object;
    Object.Resize();

    return 0;
}

GCC编译成功,但MSVC报如下错误:

error C7595: 'ClassT::GetSize': call to immediate function is not a constant expression

我错过了什么吗?或者它真的是 MSVC 错误?

编译器版本:x86-64 gcc 10.2x64 msvc v19.28。 (Link to godbolt)

这看起来像是一个 MSVC 错误。它甚至可能与现有的相同 - #1224555.

最小示例:

consteval int test() { return 0; }

int main() {
    return test(); // error C7595: 'test': call to immediate function is not a constant expression
}