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

            Bug ID: 116531
           Summary: Forward declaration with std::vector does not compile
                    with -O on arm
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: homar at riseup dot net
  Target Milestone: ---

Created attachment 59025
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59025&action=edit
Preprocessed source

The following minimal program does not compile on armel/armhf with -O. It
however *does* compile without the optimization flag, and with or without -O on
amd64 and other architectures.

$ cat fwdecl.cc
#include <vector>
class Elem;
struct List : std::vector<Elem> {
    List() {}
};
struct Elem {};

$ g++ -std=c++23 fwdecl.cc -c          # works

$ g++ -std=c++23 fwdecl.cc -c -O -v    # doesn't
Using built-in specs.
COLLECT_GCC=g++
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 14.2.0-2'
--with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr
--with-gcc-major-version-only --program-suffix=-14
--program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-libitm --disable-libquadmath
--disable-libquadmath-support --enable-plugin --enable-default-pie
--with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-sjlj-exceptions --with-arch=armv7-a+fp --with-float=hard
--with-mode=thumb --disable-werror --enable-checking=release
--build=arm-linux-gnueabihf --host=arm-linux-gnueabihf
--target=arm-linux-gnueabihf
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Debian 14.2.0-2) 
COLLECT_GCC_OPTIONS='-std=c++23' '-c' '-O' '-v' '-shared-libgcc' 
'-mfloat-abi=hard' '-mtls-dialect=gnu' '-mthumb' '-mlibarch=armv7-a+fp'
'-march=armv7-a+fp'
 /usr/libexec/gcc/arm-linux-gnueabihf/14/cc1plus -quiet -v -imultilib .
-imultiarch arm-linux-gnueabihf -D_GNU_SOURCE fwdecl.cc -D_TIME_BITS=64
-D_FILE_OFFSET_BITS=64 -quiet -dumpbase fwdecl.cc -dumpbase-ext .cc
-mfloat-abi=hard -mtls-dialect=gnu -mthumb -mlibarch=armv7-a+fp
-march=armv7-a+fp -O -std=c++23 -version -o /tmp/ccASUFF5.s
GNU C++23 (Debian 14.2.0-2) version 14.2.0 (arm-linux-gnueabihf)
        compiled by GNU C version 14.2.0, GMP version 6.3.0, MPFR version
4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=97 --param ggc-min-heapsize=127238
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf/c++/14"
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory
"/usr/lib/gcc/arm-linux-gnueabihf/14/include-fixed/arm-linux-gnueabihf"
ignoring nonexistent directory
"/usr/lib/gcc/arm-linux-gnueabihf/14/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/arm-linux-gnueabihf/14/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/14
 /usr/include/arm-linux-gnueabihf/c++/14
 /usr/include/c++/14/backward
 /usr/lib/gcc/arm-linux-gnueabihf/14/include
 /usr/local/include
 /usr/include/arm-linux-gnueabihf
 /usr/include
End of search list.
Compiler executable checksum: a94e6b605e56d9c12d47731d81ae510f
In file included from /usr/include/c++/14/vector:66,
                 from fwdecl.cc:1:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'constexpr
std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = Elem; _Alloc =
std::allocator<Elem>]':
/usr/include/c++/14/bits/stl_vector.h:531:7:   required from here
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:369:49: error: invalid use of incomplete
type 'class Elem'
  369 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
fwdecl.cc:2:7: note: forward declaration of 'class Elem'
    2 | class Elem;
      |       ^~~~

Reply via email to