https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105178
Bug ID: 105178 Summary: g++ incorrectly reports invalid use of incomplete type Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: oss.abde.sassi at gmail dot com Target Milestone: --- Created attachment 52761 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52761&action=edit self-contained small example to reproduce the error g++ 11.20.1 incorrectly reports an invalid use of incomplete type when compiling the attached code in main.cpp. Note that changing the `TransitionTo` class constructor to any of the following forms will make the compiler compile the code with no error: // These will not produce an error: TransitionTo() : data_{} { } TransitionTo(int number = 0, std::any data = {}) : data_{std::move(data)} { } TransitionTo(int number, std::any data = {}) : data_{std::move(data)} { } Command used: ------------- gcc -v -save-temps -std=c++17 -o test-incomplete-type main.cpp > cmdline-output.txt 2>&1 Output from command ------------------- Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20220127/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++17' '-o' 'test-incomplete-type' '-mtune=generic' '-march=x86-64' '-dumpdir' 'test-incomplete-type-' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1plus -E -quiet -v -D_GNU_SOURCE main.cpp -mtune=generic -march=x86-64 -std=c++17 -fpch-preprocess -o test-incomplete-type-main.ii ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/11/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11 /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/x86_64-redhat-linux /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/backward /usr/lib/gcc/x86_64-redhat-linux/11/include /usr/local/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++17' '-o' 'test-incomplete-type' '-mtune=generic' '-march=x86-64' '-dumpdir' 'test-incomplete-type-' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1plus -fpreprocessed test-incomplete-type-main.ii -quiet -dumpdir test-incomplete-type- -dumpbase main.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++17 -version -o test-incomplete-type-main.s GNU C++17 (GCC) version 11.2.1 20220127 (Red Hat 11.2.1-9) (x86_64-redhat-linux) compiled by GNU C version 11.2.1 20220127 (Red Hat 11.2.1-9), GMP version 6.2.0, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++17 (GCC) version 11.2.1 20220127 (Red Hat 11.2.1-9) (x86_64-redhat-linux) compiled by GNU C version 11.2.1 20220127 (Red Hat 11.2.1-9), GMP version 6.2.0, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: e80ddce1451d1b9471a6adee59f3d39d In file included from /usr/include/c++/11/bits/move.h:57, from /usr/include/c++/11/bits/stl_pair.h:59, from /usr/include/c++/11/utility:70, from /usr/include/c++/11/tuple:38, from main.cpp:3: /usr/include/c++/11/type_traits: In instantiation of ‘struct std::__and_<std::__not_<std::integral_constant<bool, false> >, std::is_copy_constructible<TransitionTo<SecondState> > >’: /usr/include/c++/11/type_traits:2215:11: required by substitution of ‘template<class ... _Cond> using _Require = std::__enable_if_t<std::__and_< <template-parameter-1-1> >::value> [with _Cond = {std::__not_<std::integral_constant<bool, false> >, std::is_copy_constructible<TransitionTo<SecondState> >}]’ /usr/include/c++/11/any:187:8: required by substitution of ‘template<class _Tp, class _VTp, class _Mgr, class> std::any::any(_Tp&&) [with _Tp = const TransitionTo<SecondState>&; _VTp = TransitionTo<SecondState>; _Mgr = std::any::_Manager_external<TransitionTo<SecondState> >; <template-parameter-1-4> = <missing>]’ /usr/include/c++/11/type_traits:946:30: required from ‘struct std::__is_constructible_impl<TransitionTo<SecondState>, const TransitionTo<SecondState>&>’ /usr/include/c++/11/type_traits:977:12: required from ‘struct std::__is_copy_constructible_impl<TransitionTo<SecondState>, true>’ /usr/include/c++/11/type_traits:984:12: required from ‘struct std::is_copy_constructible<TransitionTo<SecondState> >’ /usr/include/c++/11/type_traits:3179:33: required from ‘constexpr const bool std::is_copy_constructible_v<TransitionTo<SecondState> >’ /usr/include/c++/11/variant:288:5: required from ‘constexpr const bool std::__detail::__variant::_Traits<TransitionTo<SecondState>, DoNothing>::_S_copy_ctor’ /usr/include/c++/11/variant:1317:11: required from ‘class std::variant<TransitionTo<SecondState>, DoNothing>’ main.cpp:35:28: required from ‘struct OneOf<TransitionTo<SecondState>, DoNothing>’ main.cpp:71:8: required from ‘struct Maybe<TransitionTo<SecondState> >’ main.cpp:103:43: required from here /usr/include/c++/11/type_traits:152:12: error: invalid use of incomplete type ‘std::conditional<true, std::is_copy_constructible<TransitionTo<SecondState> >, std::__not_<std::integral_constant<bool, false> > >::type’ {aka ‘struct std::is_copy_constructible<TransitionTo<SecondState> >’} 152 | struct __and_<_B1, _B2> | ^~~~~~~~~~~~~~~~ In file included from /usr/include/c++/11/bits/move.h:57, from /usr/include/c++/11/bits/stl_pair.h:59, from /usr/include/c++/11/utility:70, from /usr/include/c++/11/tuple:38, from main.cpp:3: /usr/include/c++/11/type_traits:984:12: note: declaration of ‘std::conditional<true, std::is_copy_constructible<TransitionTo<SecondState> >, std::__not_<std::integral_constant<bool, false> > >::type’ {aka ‘struct std::is_copy_constructible<TransitionTo<SecondState> >’} 984 | struct is_copy_constructible | ^~~~~~~~~~~~~~~~~~~~~