https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101371
Bug ID: 101371 Summary: constexpr expansions trigger internal Compiler Error Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: warren_graeme at yahoo dot co.uk Target Milestone: --- Created attachment 51115 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51115&action=edit preprocessed source code Hello, When attempting to compile a C++ function with gcc I have triggered an Internal Compiler Error. I achieved this with the following commands: g++-7 --std=c++17 -E init.cc > init.ii g++-7 --std=c++17 -c init.ii 1) the peccant function (init.cc) follows: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include <array> #include <bitset> using namespace std; constexpr unsigned short N_citruss = 8; enum class berry: unsigned{cran, straw, rasp, bil, black, huckle, elder, goose}; constexpr berry operator++(berry& b, int) noexcept { return b = berry(static_cast<int>(b) + 1); } struct berry_set_CX{ bitset<8> bset; constexpr berry_set_CX(const bitset<8>& bits) noexcept: bset(bits) {} constexpr berry_set_CX(const char bits) noexcept: bset(bits) {} constexpr berry_set_CX() noexcept : bset() {} constexpr berry_set_CX(const berry_set_CX& rhs) noexcept : bset(rhs.bset) {} }; struct bersets_by_citrus_CX{ array<berry_set_CX, N_citruss> berrysets; }; struct entree0_CX{ bersets_by_citrus_CX passes; constexpr entree0_CX(const bersets_by_citrus_CX& bsbc) noexcept : passes(bsbc) {} }; struct berrybox_CX{ constexpr entree0_CX make_entree() const noexcept { bersets_by_citrus_CX bsbc {}; return entree0_CX(bsbc); } constexpr berrybox_CX(berry w, berry_set_CX hs) noexcept {} }; void init() noexcept{ const berry_set_CX fixed(bitset<8>(1)); for (berry root_berry = berry::cran; root_berry <= berry::goose; root_berry++){ berrybox_CX nu_cs0(root_berry, fixed); const entree0_CX& pas = nu_cs0.make_entree(); } return; } -------------------------------------------------------------------------- 2) the preprocessed source file (init.ii) is attached; 3) the compiler version used (gcc -v output) is: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/7/lto-wrapper OFFLOAD_TARGET_NAMES=hsa:nvptx-none Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,ada,go --enable-offload-targets=hsa,nvptx-none, --without-cuda-driver --enable-checking=release --disable-werror --with-gxx-include-dir=/usr/include/c++/7 --enable-ssp --disable-libssp --disable-libvtv --disable-libcc1 --disable-plugin --with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-7 --without-system-libunwind --enable-multilib --with-arch-32=x86-64 --with-tune=generic --build=x86_64-suse-linux --host=x86_64-suse-linux Thread model: posix gcc version 7.5.0 (SUSE Linux) -------------------------------------------------------------------------- 4) the compiler output is: i+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ init.cc: In function ‘void init()’: init.cc:40:46: in constexpr expansion of ‘berrybox_CX::make_entree() const()’ init.cc:40:46: in constexpr expansion of ‘entree0_CX(((const bersets_by_citrus_CX&)(& bsbc)))’ init.cc:25:79: in constexpr expansion of ‘((entree0_CX*)this)->entree0_CX::passes.bersets_by_citrus_CX::bersets_by_citrus_CX(bsbc)’ init.cc:19:8: in constexpr expansion of ‘((bersets_by_citrus_CX*)this)->bersets_by_citrus_CX::berrysets.std::array<berry_set_CX, 8>::array(bersets_by_citrus_CX::berrysets)’ init.cc:40:46: in constexpr expansion of ‘berry_set_CX(std::array<berry_set_CX, 8>::_M_elems[0])’ init.cc:40:46: internal compiler error: in cxx_eval_component_reference, at cp/constexpr.c:2479 const entree0_CX& pas = nu_cs0.make_entree(); ^ Please submit a full bug report, with preprocessed source if appropriate. See <https://bugs.opensuse.org/> for instructions. -------------------------------------------------------------------------- Initially the program which incorporated this function was developed under OpenSuse Leap 42.3 . The default compiler on that OS did not support the constexpr functionality I needed, so I installed g++-7 and used that. The code, including this function, compiled (and ran) correctly. Later I upgraded to OpenSuse Leap 15.2, my present OS; and as I had not changed my code I was not expecting trouble. But it fell over as described. I was puzzled as I was using the 15.2 default compiler, namely g++-7. However I see now that there has been more than one edition of gcc-7, so if I had silently changed from an earlier to a later version, there could be changes which trigger the ICE. Unfortunately I no longer have Leap 42.3 so have no record of which edition of gcc-7 I used then. I have tried compiling with gccs -8, -9 and -10: they all produce the same output as gcc-7 above, except with different line numbers in "constexpr.c". Yours faithfully, Graeme A. Warren