https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86274
Bug ID: 86274 Summary: SEGFAULT when logging std::to_string(NAN) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: floop at floop dot cz Target Milestone: --- Originally reported here: https://svn.boost.org/trac10/ticket/13611, but Boost developers claim the problem is probably in the compiler, not Boost. Consider the following code: #include <climits> #include <boost/log/trivial.hpp> int main() { BOOST_LOG_TRIVIAL(info) << std::to_string(std::numeric_limits<double>::quiet_NaN()); } When compiled with the following command: g++ -std=c++17 -DBOOST_ALL_DYN_LINK -pthread -lboost_log -O3 test.cpp It crashes with SEGFAULT in std::string constructor: #0 0x0000555555556221 in std::char_traits<char>::copy (__n=3, __s2=0x7fffffffd4e0 "nan", __s1=<optimized out>) at /usr/include/c++/7/bits/char_traits.h:350 Note that the SEGFAULT does not happen with -O2, but only -O3. Clang does not seem to be affected. System info: [floop@pine /tmp ]$ g++ -v ... gcc version 8.1.1 20180531 (GCC) [floop@pine /tmp ]$ uname -a Linux pine 4.16.13-2-ARCH #1 SMP PREEMPT Fri Jun 1 18:46:11 UTC 2018 x86_64 GNU/Linux Others have been able to reproduce this with gcc 7.3 (see the bug report on https://svn.boost.org/trac10/ticket/13611). Thank you for your help and have a great day!