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

            Bug ID: 127476
           Summary: <memory> unconditionally includes <bits/indirect.h> in
                    freestanding mode
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: longfeiqiu2012 at gmail dot com
  Target Milestone: ---

I built GCC 16.2.0 from source with the following configuration:

export TARGET=aarch64-none-elf
export PREFIX=/opt/aarch64-none-elf
export PROG_PREFIX=aarch64-none-elf-
../gcc-16.2.0/configure \
--target=$TARGET \
--prefix=$PREFIX \
--program-prefix=$PROG_PREFIX \
--with-as=/opt/aarch64-none-elf/bin/aarch64-none-elf-as \
--with-ld=/opt/aarch64-none-elf/bin/aarch64-none-elf-ld \
--disable-bootstrap \
--without-headers \
--with-newlib \
--disable-hosted-libstdcxx \
--enable-languages=c,c++

After installing this version of GCC, create a file test.cpp with one line:

#include <memory>

Then invoke g++ as follows:
aarch64-none-elf-g++ -std=c++26 -E -o test.ii test.cpp

g++ reports it could not find <bits/indirect.h>:

In file included from test.cpp:1:
/opt/aarch64-none-elf/aarch64-none-elf/include/c++/16.2.0/memory:101:12: fatal
error: bits/indirect.h: No such file or directory
  101 | #  include <bits/indirect.h>
      |

This seems to be due to <memory> unconditionally including <bits/indirect.h> if
std is set to c++26.

libstdc++-v3/include/std/memory:101-103 reads:

#if __cplusplus > 202302L
#  include <bits/indirect.h>
#endif

I was able to work around this by adding a #if _GLIBCXX_HOSTED guard around it.
I checked that the latest trunk version still does not have this guard.

Either add a hosted guard around this include or install the missing header to
freestanding builds.
  • [Bug libstdc++/127476] New: &... longfeiqiu2012 at gmail dot com via Gcc-bugs

Reply via email to