-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"miscompilationregression:20Regression in 20 releaseRegression in 20 release
Description
https://godbolt.org/z/5s4GazKEP
#include <print>
#include <numeric>
#include <vector>
#include <string>
struct foo {std::string bar;};
const std::vector<foo> foos = {{"1"}, {"2"}, {"3"}};
size_t count(const std::vector<foo>& input = foos) {
size_t c = 0;
for (const foo& f : input) {
c += f.bar.size();
}
return c;
}
int main() {
std::print("answer 1: {}\n", count());
std::print("answer 2: {}\n", count({{"1"}, {"2"}}));
std::print("answer 3: {}\n", count());
}
When compiled in clang 20 we get 3 printed 3 times, while in clang 19 we get 3, 2, 3 printed. I suspect some kind of over-aggressive optimization is assuming the input to this function is always foos
.
yaoxinliu and mihaitodor
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"miscompilationregression:20Regression in 20 releaseRegression in 20 release
Type
Projects
Status
Done