7

代码:

#include <iostream>
#include <string>
#include <fstream>
int main(int argc, char *argv[]) {
    std::string filename = "dummyfile";
    std::ifstream infile(filename);
    std::string line;
    std::getline(infile, line);
    return 0;
}

编译并链接到:

g++-7 -std=c++17 -flto mycode.cpp

结果是:

* `./a.out' 中的错误:free():无效指针:0x0000000000602200 *中止(核心转储)

-flto它在没有标志的情况下编译并运行良好。保持-flto但更改-std=c++17-std=c++14or-std=c++11也会使其工作。所以似乎 和 的组合有些flto东西c++17

gdb 结果:

#0  0x00007ffff7a4acc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff7a4e0d8 in __GI_abort () at abort.c:89
#2  0x00007ffff7a87f24 in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7ffff7b966c8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff7a941fe in malloc_printerr (ptr=<optimized out>, str=0x7ffff7b927b9 "free(): invalid pointer", action=1) at malloc.c:4996
#4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3840
#5  0x00007ffff77c6e25 in std::string::reserve(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff77c706a in std::string::append(char const*, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff7784aba in std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x000000000040130b in std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
#9  0x00000000004010cd in main () 

编译器和操作系统:g++-7 (Ubuntu 7.2.0-1ubuntu1~14.04) 7.2.0

4

0 回答 0