[Bug middle-end/104081] Variable optimized out despite -Og
matthias at urlichs dot de
gcc-bugzilla@gcc.gnu.org
Tue Jan 18 08:51:54 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104081
--- Comment #3 from Matthias Urlichs <matthias at urlichs dot de> ---
Sure.
gcc -Og -g -std=c++17 -lstdc++ /tmp/test.cpp
#include <string_view>
#include <string>
void throw_invalid(const char *a, std::string_view b) {
(void)a; (void)b;
throw;
}
int64_t str_atoi(std::string_view data)
{
const std::string_view odata = data;
int64_t val = 0;
bool neg;
if(data.length() == 0)
throw_invalid("empty",odata);
neg = data.front() == '-';
if(neg) {
data.remove_prefix(1);
if(data.length() == 0)
throw_invalid("empty",data);
}
for (const auto& c : data) {
if (c < '0' || '9' < c)
throw_invalid("not a number",odata);
val = val*10 + c-'0';
}
if(neg)
val = -val;
return val;
}
int main() {
volatile int x = str_atoi("nope");
}
More information about the Gcc-bugs
mailing list