https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92522
Bug ID: 92522 Summary: valid code using deque throws bad_alloc when compiled with -flto Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: johnilacqua at hotmail dot com Target Milestone: --- Minimal example: //sample.cc #include <deque> std::deque<int> test; //main.cc #include <deque> extern std::deque<int> test; static const auto sample = test; int main() {} compile command: g++-9 -flto sample.cc main.cc g++-9 --version g++-9 (Ubuntu 9.2.1-17ubuntu1~16.04) 9.2.1 20191102 Running the resulting binary throws bad_alloc. Running with valgrind displays output: **168** new/new[] failed and should throw an exception, but Valgrind **168** cannot throw exceptions and so is aborting instead. Sorry. ==168== at 0x4C2D96C: ??? (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==168== by 0x4C2E165: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==168== by 0x40113F: __gnu_cxx::new_allocator<int*>::allocate(unsigned long, void const*) (in /home/john/test/a.out) ==168== by 0x40103D: std::allocator_traits<std::allocator<int*> >::allocate(std::allocator<int*>&, unsigned long) (in /home/john/test/a.out) ==168== by 0x400E43: std::_Deque_base<int, std::allocator<int> >::_M_allocate_map(unsigned long) (in /home/john/test/a.out) ==168== by 0x400B7B: std::_Deque_base<int, std::allocator<int> >::_M_initialize_map(unsigned long) (in /home/john/test/a.out) ==168== by 0x4015E6: std::_Deque_base<int, std::allocator<int> >::_Deque_base(std::allocator<int> const&, unsigned long) (in /home/john/test/a.out) ==168== by 0x40145A: std::deque<int, std::allocator<int> >::deque(std::deque<int, std::allocator<int> > const&) (in /home/john/test/a.out) ==168== by 0x402005: __static_initialization_and_destruction_0(int, int) [clone .lto_priv.1] (in /home/john/test/a.out) ==168== by 0x40202E: _GLOBAL__sub_I_main (in /home/john/test/a.out) ==168== by 0x402039: _sub_I_65535_0.4643 (in /home/john/test/a.out) ==168== by 0x40209C: __libc_csu_init (in /home/john/test/a.out)