Many operations with volatile were deprecated in c++20 (see https://en.cppreference.com/w/cpp/language/cv)
So.... when I used very popular glm library(https://github.com/g-truc/glm) in my project I got warnings around this code (file type_half.inl
):
GLM_FUNC_QUALIFIER float overflow()
{
volatile float f = 1e10;
for(int i = 0; i < 10; ++i)
f *= f; // this will overflow before the for loop terminates
return f;
}
This code used to force causing floating point overflow, and obviously volatile here used to turn off optimization around f. Otherwise compiler can just throw out this cycle as useless.
How this code may be fixed for modern standards of c++, like c++20 and above?