This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/81517] New: Unhelpful what() for uninitialized threads backend (in __gthread_once)
- From: "chris.j.leonard at gmx dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 22 Jul 2017 17:46:57 +0000
- Subject: [Bug libstdc++/81517] New: Unhelpful what() for uninitialized threads backend (in __gthread_once)
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81517
Bug ID: 81517
Summary: Unhelpful what() for uninitialized threads backend (in
__gthread_once)
Product: gcc
Version: 7.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: chris.j.leonard at gmx dot com
Target Milestone: ---
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --disable-multilib --disable-werror
--enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 7.1.1 20170630 (GCC)
$ cat example.cpp
#include <mutex>
int main()
{
std::once_flag flag;
std::call_once(flag, []{});
}
$ g++ -Wall -Wextra example.cpp -o example
Compiler gives no output and succeeds (as expected)
$ ./example
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
The what() message, called from __gthread_once, is "Unknown error" and the
error code it receives. Reading the header code reveals -1 is returned if a
global thread object was not correctly initialized, which should illuminate the
mistake: not linking libpthread.
This is a typical enough mistake, giving a more useful what() message like
"pthread missing / not initialized" would save a programmer time in this
instance, or help them where they might have been totally lost.