[Bug c++/60750] [4.8/4.9 Regression] double free after std::move on string inside throw when compiled with optimization
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Apr 4 11:22:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60750
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Markus Trippelsdorf from comment #5)
> -fno-ipa-pure-const "fixes" the issue.
local pure const computes thrower() as noreturn. Adding noreturn to it in
the source reproduces the problem even with -fno-ipa-pure-const (but not
with -O0 or GCC 4.7).
Thus, adjusted testcase:
#include <string>
#include <stdexcept>
#include <stdio.h>
const std::string err_prefix = "Problem: ";
void __attribute__((noreturn)) thrower (std::string msg) {
throw std::runtime_error(err_prefix + std::move(msg));
}
int main(int argc, char **argv) {
try {
std::string base = "hello";
thrower(std::move(base));
} catch (const std::runtime_error &e) {
printf( "Leaving catch. %s\n", e.what());
}
printf( "exiting nbd\n");
return 0;
}
More information about the Gcc-bugs
mailing list