#1077657 g++-14-arm-linux-gnueabihf: Forward declaration of std::vector does not compile with -O

Package:
g++-14-arm-linux-gnueabihf
Source:
g++-14-arm-linux-gnueabihf
Description:
GNU C++ compiler for arm-linux-gnueabihf architecture
Submitter:
Gábor Németh
Date:
2024-08-29 10:09:04 UTC
Severity:
normal
#1077657#5
Date:
2024-07-31 13:39:43 UTC
From:
To:
Dear Maintainer,

I have the following minimal program that does not compile on armhf with
-O. It however *does* compile without the optimization flag, or with or
without -O on amd64 and other architectures. (I'm maintaining
msc-generator that FTBFS [1] on armhf/armel due to this.)

The program and transcript on armhf-in-qemu follows:

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

$ g++ -std=c++23 fwdecl.cc -S -O
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;
      |       ^~~~

$ g++ -std=c++23 fwdecl.cc -S  # exits OK

$ g++ --version
g++ (Debian 14.1.0-5) 14.1.0
Copyright (C) 2024 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.

Caveat: if the List ctor is defaulted, it compiles. As does on amd64 for
the reference:

$ g++ --version
g++ (Debian 14.1.0-5) 14.1.0
Copyright (C) 2024 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.

$ uname -a
Linux 814523ba7101 6.8.12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.8.12-1
(2024-05-31) x86_64 GNU/Linux

$ g++ -std=c++23 fwdecl.cc -S -O

$ g++ -std=c++23 fwdecl.cc -S

$ dpkg -l | grep 'g++'
ii  g++                                   4:14.1.0-2
  amd64        GNU C++ compiler
ii  g++-14                                14.1.0-5
  amd64        GNU C++ compiler
ii  g++-14-x86-64-linux-gnu               14.1.0-5
  amd64        GNU C++ compiler for x86_64-linux-gnu architecture
ii  g++-x86-64-linux-gnu                  4:14.1.0-2
  amd64        GNU C++ compiler for the amd64 architecture

BR,
Gábor

[1]
https://buildd.debian.org/status/fetch.php?pkg=msc-generator&arch=armhf&ver=8.6.2-1&stamp=1722276981&raw=0

#1077657#10
Date:
2024-08-11 13:32:51 UTC
From:
To: