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

            Bug ID: 120202
           Summary: ICE with constexpr function for constant expression
           Product: gcc
           Version: 12.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: calvin at cmpct dot info
  Target Milestone: ---

I was shuffling around definitions in a class for header-only library, and
managed to ICE g++ in 10 and 12. I can reproduce this on GNU/Linux on x86_64
(from Gentoo) as well on AIX, which is why I'm filing upstream. This appears to
no longer ICE in newer GCC (tested with 14), but still gives a somewhat
confusing error message with a "because:" and no reason afterward.

Reduced example:

```
#include <array>
template <typename... TArgs> struct ILEArglist {
  using Sizes = std::array<std::size_t, sizeof...(TArgs)>;
  static constexpr auto size() {
    Sizes &offsets_c = offsets;
    return 0;
  }
  std::array<char, size()> offsets();
};
auto arglist = ILEArglist<>()
```

Error:

```
g++-12 -std=c++14 -Wall -Wextra evil.cpp
evil.cpp: In instantiation of ‘static constexpr auto ILEArglist<TArgs>::size()
[with TArgs = {}]’:
evil.cpp:8:24:   required from ‘struct ILEArglist<>’
evil.cpp:10:29:   required from here
evil.cpp:5:12: warning: unused variable ‘offsets_c’ [-Wunused-variable]
    5 |     Sizes &offsets_c = offsets;
      |            ^~~~~~~~~
evil.cpp: In instantiation of ‘struct ILEArglist<>’:
evil.cpp:10:29:   required from here
evil.cpp:8:28: internal compiler error: in coerce_template_parms, at
cp/pt.cc:9219
    8 |   std::array<char, size()> offsets();
      |                            ^~~~~~~
0x19344d3 internal_error(char const*, ...)
        ???:0
0x688ffb fancy_abort(char const*, int, char const*)
        ???:0
0x80b3ff tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x82754f instantiate_class_template(tree_node*)
        ???:0
0x8600c3 complete_type(tree_node*)
        ???:0
0x86016b complete_type_or_maybe_complain(tree_node*, tree_node*, int)
        ???:0
0x87b3af build_functional_cast(unsigned int, tree_node*, tree_node*, int)
        ???:0
0x7ea94b c_parse_file()
        ???:0
0x8ca7f7 c_common_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
```

I initially simplified the code that ICE'd by hand, then used cvise to reduce
it further; that initial simplification is here:
https://gist.github.com/NattyNarwhal/6923de2ad3428ba33cc1cd9487bdef89

(Apologies if the reduced sample doesn't make as much sense; I'm still learning
modern C++ and I'm not familar with cvise.)

Version:

```
Using built-in specs.
COLLECT_GCC=g++-12
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-unknown-linux-gnu/12/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-12.4.1_p20241219/work/gcc-12-20241219/configure
--host=aarch64-unknown-linux-gnu --build=aarch64-unknown-linux-gnu
--prefix=/usr --bindir=/usr/aarch64-unknown-linux-gnu/gcc-bin/12
--includedir=/usr/lib/gcc/aarch64-unknown-linux-gnu/12/include
--datadir=/usr/share/gcc-data/aarch64-unknown-linux-gnu/12
--mandir=/usr/share/gcc-data/aarch64-unknown-linux-gnu/12/man
--infodir=/usr/share/gcc-data/aarch64-unknown-linux-gnu/12/info
--with-gxx-include-dir=/usr/lib/gcc/aarch64-unknown-linux-gnu/12/include/g++-v12
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/aarch64-unknown-linux-gnu/12/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--disable-libunwind-exceptions --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo
12.4.1_p20241219 p2' --with-gcc-major-version-only --enable-libstdcxx-time
--enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --disable-multilib
--disable-fixed-point --enable-libgomp --disable-libssp --disable-libada
--disable-standard-branch-protection --disable-systemtap
--disable-valgrind-annotations --disable-vtable-verify --disable-libvtv
--with-zstd --without-isl --enable-default-pie --enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.4.1 20241219 (Gentoo 12.4.1_p20241219 p2) 
```

Reply via email to