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

            Bug ID: 128880
           Summary: Missing declaration/definition of __throw_logic_error
                    in freestanding library implementation
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.morgner at gmail dot com
  Target Milestone: ---

Created attachment 66227
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66227&action=edit
Patch to add the missing function

When trying to compile the following code for a freestanding environment,
compilation fails because there is no declaration (or definition) of
`__thow_logic_error` available in the freestanding library:

#include <bitset>

auto main() -> int {
  auto obj = std::bitset<256>{};
  return obj.count();
}

Compiler invocation:

x86_64-pc-elf-g++ test.cpp

Compiler output:

In file included from test.cpp:1:
/home/sophia/.opt/teachos-toolchain/x86_64-pc-elf/include/c++/16.2.0/bitset: In
constructor 'std::bitset<_Nb>::bitset(const _CharT*, typename
std::__bitset::__string<_CharT>::size_type, _CharT, _CharT)':
/home/sophia/.opt/teachos-toolchain/x86_64-pc-elf/include/c++/16.2.0/bitset:1069:13:
error: there are no arguments to '__throw_logic_error' that depend on a
template parameter, so a declaration of '__throw_logic_error' must be available
[-Wtemplate-body]
 1069 |             __throw_logic_error(__N("bitset::bitset(const _CharT*,
...)"));
      |             ^~~~~~~~~~~~~~~~~~~
/home/sophia/.opt/teachos-toolchain/x86_64-pc-elf/include/c++/16.2.0/bitset:1069:13:
note: (if you use '-fpermissive', G++ will accept your code, but allowing the
use of an undeclared name is deprecated)

Compiler version (output of x86_64-pc-elf-gcc):

Using built-in specs.
COLLECT_GCC=x86_64-pc-elf-gcc
COLLECT_LTO_WRAPPER=/home/sophia/.opt/teachos-toolchain/bin/../libexec/gcc/x86_64-pc-elf/16.2.0/lto-wrapper
Target: x86_64-pc-elf
Configured with: ../gcc-16.2.0/configure --disable-hosted-libstdcxx
--disable-nls --disable-shared --disable-tm-clone-registry --disable-threads
--disable-wchar_t --enable-initfini-array --enable-languages=c,c++
--enable-plugin --enable-multilib --prefix=/opt/toolchain
--target=x86_64-pc-elf --with-newlib CPPFLAGS=-I/opt/static-deps/include
LDFLAGS=-L/opt/static-deps/lib
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 16.2.0 (GCC) 

The reason is that "libstdc++-v3/include/bits/stdexcept_throwfwd.h" is missing
a definition for __throw_logic_error in the non-hosted case.

A patch (against releases/gcc-16) is attached. The patch only includes the
addition of __throw_logic_error, since it is not clear if the other __throw_*
functions have been left out intentionally. I chose to insert the definition at
the front of the block to mirror the order in the hosted block.
  • [Bug libstdc++/128880] New: Mi... felix.morgner at gmail dot com via Gcc-bugs

Reply via email to