Closed as not planned
Closed as not planned
Description
Hi !
I'm encoutering a problem from clang19.1.0 (clang20.1.0 also has it) with this kind of code :
https://godbolt.org/z/WWdqcvj6h
double recursiveEval(int n, const double a) {
return n <= 0 ? 0 : a + recursiveEval(n - 1, a);
}
double eval(const std::vector<double>& emptyVector) {
std::vector<double> vec;
for (const double& it : emptyVector) {
std::cerr << "BIG ERROR !! I should not be here" << std::endl;
vec.push_back(recursiveEval(it, it));
}
return recursiveEval(vec.size(), vec[0]);
}
int main(int argc, char **argv) {
std::vector<double> coefs;
eval(coefs);
return 0;
}
It segfaults but that is not the problem. The problem is we go into the forloop whereas the vector emptyVector is empty.
The problem disappears when (any of these):
- vec or emptyVector are not empty
vec[0]
is replaced by a prvalue- the line
return recursiveEval(vec.size(), vec[0]);
is deleted (replaced by any return).
Thanks for your help