I have a consteval crc32 function that works just fine on compile time. I want this function to be used in another constant inline function.
Here is a code example for a better understanding:
unsigned int consteval strsum(const std::string str) {
auto n = 0;
for (int i = 0; i < str.size(); i++) n += str.at(i);
return n;
}
void _printHash(const unsigned int hash) {
printf("%d", hash);
}
__forceinline void printHash(const std::string str) {
_printHash(strsum(str));
}
int main(int argc, char* argv[]) {
printHash("abc");
}
I want this code to compile to just:
int main(int argc, char* argv[]) {
_printHash(/* hash constant */);
}
Instead, i get a C7595 error: A call to a consteval function is not a constant expression.
Is there any way to acheive wanted behavior on MSVC?