https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99650
Bug ID: 99650 Summary: ICE when trying to form reference to void in structured binding Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: csaba_22 at yahoo dot co.uk Target Milestone: --- Created attachment 50423 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50423&action=edit gzipped preprocessor output The following code leads to an internal compiler error: #include <stdint.h> #include <tuple> #include <string> struct Cow{}; struct Dog{}; struct Horse{}; // of course template <typename ... Ts> struct meow{ template<size_t Idx> decltype(auto) get() { if constexpr (Idx == 0) { return Cow{}; } else if constexpr (Idx == 1) { return Dog{}; } else if constexpr (Idx == 2) { return Horse{}; } } }; template <typename ... Ts> meow<Ts...> kitty() { return meow<Ts...>{}; } namespace std { template<typename ... Ts> struct tuple_size< meow<Ts...> > : std::integral_constant<std::size_t, sizeof...(Ts)> {}; template< std::size_t Idx, class... Ts > struct tuple_element< Idx, meow<Ts...> > { using type = decltype( std::declval< meow<Ts...> >().template get<Idx>() ); }; } int main(int argc, char const *argv[]) { auto && [ moo, woof, neigh, vv ] = kitty<Cow, Dog, Horse, void>(); } $ g++ -v g++ -g -std=gnu++17 -fdiagnostics-color -g tuple-protocol-template.cpp -o tuple-protocol-template Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --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-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) tuple-protocol-template.cpp: In function ‘int main(int, const char**)’: tuple-protocol-template.cpp:43:69: internal compiler error: in build_target_expr_with_type, at cp/tree.c:722 auto && [ moo, woof, neigh, vv ] = kitty<Cow, Dog, Horse, void>(); ^ Also fails with: * gcc version 11.0.1 20210317 (experimental) (Compiler-Explorer-Build) * GNU C++17 (Compiler-Explorer-Build) version 10.2.0 (x86_64-linux-gnu) compiled by GNU C version 7.5.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP * GNU C++17 (Compiler-Explorer-Build) version 9.3.0 (x86_64-linux-gnu) compiled by GNU C version 7.5.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP * GNU C++17 (Compiler-Explorer-Build) version 8.3.0 (x86_64-linux-gnu) compiled by GNU C version 7.5.0, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP * GNU C++14 (GCC-Explorer-Build) version 7.1.0 (x86_64-linux-gnu) compiled by GNU C version 5.4.0 20160609, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.16.1-GMP clang 11.0.1 on godbolt reports: <source>:43:33: error: cannot form a reference to 'void' auto && [ moo, woof, neigh, vv ] = kitty<Cow, Dog, Horse, void>(); ^ <source>:43:33: note: in implicit initialization of binding declaration 'vv' https://godbolt.org/z/e18Ts6