Consider the following code:
#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 compiles it successfully, but MSVC gives the following error:
error C7595: 'ClassT::GetSize': call to immediate function is not a constant expression
Am I missing something? Or is it really an MSVC bug?
Compilers version: x86-64 gcc 10.2 and x64 msvc v19.28. (Link to godbolt)
This looks like an MSVC bug. It might even be the same as this existing one- #1224555.
Minimal example:
consteval int test() { return 0; }
int main() {
return test(); // error C7595: 'test': call to immediate function is not a constant expression
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With