https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91876

            Bug ID: 91876
           Summary: Segmentation fault when comparing
                    std::system_error::code() and
                    std::errc::invalid_argument
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lachiepoop at naver dot com
  Target Milestone: ---

I needed to check the error code of std::system_error doing my project. But
when I did that, I ended up with SIGSEGV.

foo.cpp:

#include <thread>
#include <iostream>
#include <system_error>

int main(void)
{
    std::thread t1;

    try
    {
        t1.join();
    }
    catch (const std::system_error& e)
    {
        std::cout << "System error\n";

        if (e.code() == std::errc::invalid_argument) // here in the
operator==(), running into SIGSEGV 
        {
            std::cout << e.what() << "\n";
        }
        else
        {
            throw;
        }
    }

    return 0;
}

And I compile/linked it as:

g++ -std=c++17 -O3 -Wall -pedantic -pthread foo.cpp && ./a.foo
System error
Segmentation fault (core dumped)

The stack trace shows that it had SIGSEGV in std::error_category::equivalent()

$ gdb a.out core.a.out.1569300501.5706
...
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000003603269ca2 in std::error_category::equivalent(std::error_code
const&, int) const () from /usr/lib64/libstdc++.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.192.el6.x86_64
libgcc-4.4.7-17.el6.x86_64 libstdc++-4.4.7-17.el6.x86_64
(gdb) where
#0  0x0000003603269ca2 in std::error_category::equivalent(std::error_code
const&, int) const () from /usr/lib64/libstdc++.so.6
#1  0x000000000040285f in std::operator== (__lhs=..., __rhs=...) at
/opt/rh/devtoolset-7/root/usr/include/c++/7/system_error:299
#2  0x0000000000402628 in main () at foo.cpp:17

my gcc version is:
irt...@cmiddev02.nm:~/shawn/test/join$ gcc --version
gcc (GCC) 7.2.1 20170829 (Red Hat 7.2.1-1)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Reply via email to