Spr*_*ite 4 c++ gcc visual-c++ language-lawyer c++20
考虑以下代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
GCC编译成功,但是MSVC给出以下错误:
error C7595: 'ClassT::GetSize': call to immediate function is not a constant expression
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?或者这真的是 MSVC 的错误吗?
编译器版本:x86-64 gcc 10.2和x64 msvc v19.28. (链接到神箭)
这看起来像是 MSVC 错误。它甚至可能与现有的#1224555相同。
最小的例子:
consteval int test() { return 0; }
int main() {
return test(); // error C7595: 'test': call to immediate function is not a constant expression
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
863 次 |
| 最近记录: |