【发布时间】:2021-03-31 09:54:01
【问题描述】:
考虑以下代码:
#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.2 和 x64 msvc v19.28。 (Link to godbolt)
【问题讨论】:
标签: c++ gcc visual-c++ language-lawyer c++20