You could file a bug.
I confirm the observation by njuffa, in my test case, if I change this:
float ld, val;
to this:
float ld = 0, val = 0;
then the observation is no longer reproducible. I agree that such an assignment:
val = ld;
on the first pass of the loop is UB, however I’m not sure if the scope of that UB is for the contents of the variable itself or the entire program. I’m not enough of a C++ “lawyer” to know what the compiler is allowed to do in that case. With respect to the the first pass of the loop, that assignment, and indeed the actual values of val and ld have no bearing on the output of the program (other than what an exception due to UB may “allow” the compiler to do.)
At least as a work-around, then I suggest (as njuffa did) that you initialize these variables.