Created attachment 43262 [details] Preprocessed file I encounter the following error when building a C++ source file doing some moderately deep template instantiation due to Eigen + Boost.Serialization. I cannot reproduce the same error on a minimal example, although I tried. Clang builds the same sources fine (and the resulting linked binary runs correctly). I can reproduce the same problem also with older g++ versions. // ----------------------------------------- $ g++ -v Using built-in specs. COLLECT_GCC=/usr/bin/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='Debian 7.3.0-1' --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 --with-sysroot=/ --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.3.0 (Debian 7.3.0-1) // ----------------------------------------- FAILED: CMakeFiles/gadv-backend.dir/gadv-backend/logic/petri-net.cc.o /usr/bin/g++ -Dgadv_EXPORTS -Dgadv_backend_EXPORTS -I/home/matteo/Progetti/gadv/include -Iinclude -I/home/matteo/Progetti/gadv/src/gadv-backend -isystem /usr/include/eigen3 -isystem /usr/include/pangomm-1.4 -isystem /usr/lib/x86_64-linux-gnu/pangomm-1.4/include -isystem /usr/include/glibmm-2.4 -isystem /usr/lib/x86_64-linux-gnu/glibmm-2.4/include -isystem /usr/include/cairomm-1.0 -isystem /usr/lib/x86_64-linux-gnu/cairomm-1.0/include -isystem /usr/include/sigc++-2.0 -isystem /usr/lib/x86_64-linux-gnu/sigc++-2.0/include -isystem /usr/include/pango-1.0 -isystem /usr/include/harfbuzz -isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -ftemplate-backtrace-limit=0 -fdiagnostics-color=always -O3 -DNDEBUG -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -pedantic -fstack-protector-strong -std=gnu++1z -MD -MT CMakeFiles/gadv-backend.dir/gadv-backend/logic/petri-net.cc.o -MF CMakeFiles/gadv-backend.dir/gadv-backend/logic/petri-net.cc.o.d -o CMakeFiles/gadv-backend.dir/gadv-backend/logic/petri-net.cc.o -c /home/matteo/Progetti/gadv/gadv-backend/logic/petri-net.cc In file included from /usr/include/eigen3/Eigen/Core:351:0, from /usr/include/eigen3/Eigen/SparseCore:11, from /home/matteo/Progetti/gadv/include/gadv/logic/petri-net.hh:24, from /home/matteo/Progetti/gadv/gadv-backend/logic/petri-net.cc:18: /usr/include/eigen3/Eigen/src/Core/NumTraits.h: In instantiation of ‘struct Eigen::GenericNumTraits<boost::serialization::U>’: /usr/include/eigen3/Eigen/src/Core/NumTraits.h:150:29: required from ‘struct Eigen::NumTraits<boost::serialization::U>’ /usr/include/eigen3/Eigen/src/SparseCore/SparseMatrixBase.h:109:30: required from ‘class Eigen::SparseMatrixBase<Eigen::SparseMatrix<boost::serialization::U, 0, int> >’ /usr/include/eigen3/Eigen/src/SparseCore/SparseCompressedBase.h:36:7: required from ‘class Eigen::SparseCompressedBase<Eigen::SparseMatrix<boost::serialization::U, 0, int> >’ /usr/include/boost/serialization/split_free.hpp:58:13: recursively required by substitution of ‘template<class Archive, template<class U> class SPT> void boost::serialization::load(Archive&, SPT<boost::serialization::U>&, unsigned int) [with Archive = boost::archive::xml_iarchive; SPT = <missing>]’ /usr/include/boost/serialization/split_free.hpp:58:13: required from ‘static void boost::serialization::free_loader<Archive, T>::invoke(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = Eigen::Triplet<long int, long int>]’ /usr/include/boost/serialization/split_free.hpp:74:18: required from ‘void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = Eigen::Triplet<long int, long int>]’ /home/matteo/Progetti/gadv/gadv-backend/logic/serialization-helpers.tcc:55:16: required from ‘void boost::serialization::serialize(Archive&, Eigen::Triplet<Scalar, Index>&, boost::serialization::version_type) [with Archive = boost::archive::xml_iarchive; Scalar = long int; Index = long int]’ /usr/include/boost/serialization/serialization.hpp:126:14: required from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = Eigen::Triplet<long int, long int>]’ /usr/include/boost/archive/detail/iserializer.hpp:188:40: required from ‘void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_iarchive; T = Eigen::Triplet<long int, long int>]’ /usr/include/boost/archive/detail/iserializer.hpp:120:1: required from ‘class boost::archive::detail::iserializer<boost::archive::xml_iarchive, Eigen::Triplet<long int, long int> >’ /usr/include/boost/archive/detail/iserializer.hpp:410:13: required from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::load_standard::invoke(Archive&, const T&) [with T = Eigen::Triplet<long int, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/iserializer.hpp:462:22: required from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = Eigen::Triplet<long int, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/iserializer.hpp:618:18: required from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::xml_iarchive; T = Eigen::Triplet<long int, long int>]’ /usr/include/boost/archive/detail/common_iarchive.hpp:66:22: required from ‘void boost::archive::detail::common_iarchive<Archive>::load_override(T&) [with T = Eigen::Triplet<long int, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/basic_xml_iarchive.hpp:78:9: required from ‘void boost::archive::basic_xml_iarchive<Archive>::load_override(const boost::serialization::nvp<T>&) [with T = Eigen::Triplet<long int, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/xml_iarchive.hpp:95:51: required from ‘void boost::archive::xml_iarchive_impl<Archive>::load_override(T&) [with T = const boost::serialization::nvp<Eigen::Triplet<long int, long int> >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/interface_iarchive.hpp:68:9: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = const boost::serialization::nvp<Eigen::Triplet<long int, long int> >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/serialization/collections_load_imp.hpp:72:12: required from ‘typename boost::enable_if<boost::serialization::detail::is_default_constructible<typename T::value_type>, void>::type boost::serialization::stl::collection_load_impl(Archive&, T&, boost::serialization::collection_size_type, boost::serialization::item_version_type) [with Archive = boost::archive::xml_iarchive; T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >; typename boost::enable_if<boost::serialization::detail::is_default_constructible<typename T::value_type>, void>::type = void]’ /usr/include/boost/serialization/vector.hpp:91:30: required from ‘void boost::serialization::load(Archive&, std::vector<U, Allocator>&, unsigned int, mpl_::false_) [with Archive = boost::archive::xml_iarchive; U = Eigen::Triplet<long int, long int>; Allocator = std::allocator<Eigen::Triplet<long int, long int> >; mpl_::false_ = mpl_::bool_<false>]’ /usr/include/boost/serialization/vector.hpp:159:9: required from ‘void boost::serialization::load(Archive&, std::vector<U, Allocator>&, unsigned int) [with Archive = boost::archive::xml_iarchive; U = Eigen::Triplet<long int, long int>; Allocator = std::allocator<Eigen::Triplet<long int, long int> >]’ /usr/include/boost/serialization/split_free.hpp:58:13: required from ‘static void boost::serialization::free_loader<Archive, T>::invoke(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >]’ /usr/include/boost/serialization/split_free.hpp:74:18: required from ‘void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >]’ /usr/include/boost/serialization/vector.hpp:170:37: required from ‘void boost::serialization::serialize(Archive&, std::vector<U, Allocator>&, unsigned int) [with Archive = boost::archive::xml_iarchive; U = Eigen::Triplet<long int, long int>; Allocator = std::allocator<Eigen::Triplet<long int, long int> >]’ /usr/include/boost/serialization/serialization.hpp:126:14: required from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >]’ /usr/include/boost/archive/detail/iserializer.hpp:188:40: required from ‘void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_iarchive; T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >]’ /usr/include/boost/archive/detail/iserializer.hpp:120:1: required from ‘class boost::archive::detail::iserializer<boost::archive::xml_iarchive, std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > > >’ /usr/include/boost/archive/detail/iserializer.hpp:410:13: required from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::load_standard::invoke(Archive&, const T&) [with T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/iserializer.hpp:462:22: required from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/iserializer.hpp:618:18: required from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::xml_iarchive; T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >]’ /usr/include/boost/archive/detail/common_iarchive.hpp:66:22: required from ‘void boost::archive::detail::common_iarchive<Archive>::load_override(T&) [with T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/basic_xml_iarchive.hpp:78:9: required from ‘void boost::archive::basic_xml_iarchive<Archive>::load_override(const boost::serialization::nvp<T>&) [with T = std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/xml_iarchive.hpp:95:51: required from ‘void boost::archive::xml_iarchive_impl<Archive>::load_override(T&) [with T = const boost::serialization::nvp<std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > > >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/interface_iarchive.hpp:68:9: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = const boost::serialization::nvp<std::vector<Eigen::Triplet<long int, long int>, std::allocator<Eigen::Triplet<long int, long int> > > >; Archive = boost::archive::xml_iarchive]’ /home/matteo/Progetti/gadv/gadv-backend/logic/serialization-helpers.tcc:66:62: required from ‘typename std::enable_if<std::is_convertible<Matrix*, Eigen::SparseMatrixBase<SparseDerived>*>::value, void>::type boost::serialization::load(Archive&, Matrix&, boost::serialization::version_type) [with Archive = boost::archive::xml_iarchive; Matrix = Eigen::SparseMatrix<long int, 0, long int>; typename std::enable_if<std::is_convertible<Matrix*, Eigen::SparseMatrixBase<SparseDerived>*>::value, void>::type = void]’ /usr/include/boost/serialization/split_free.hpp:58:13: required from ‘static void boost::serialization::free_loader<Archive, T>::invoke(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = Eigen::SparseMatrix<long int, 0, long int>]’ /usr/include/boost/serialization/split_free.hpp:74:18: required from ‘void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = Eigen::SparseMatrix<long int, 0, long int>]’ /home/matteo/Progetti/gadv/gadv-backend/logic/serialization-helpers.tcc:99:16: required from ‘typename std::enable_if<std::is_convertible<Matrix*, Eigen::SparseMatrixBase<SparseDerived>*>::value, void>::type boost::serialization::serialize(Archive&, Matrix&, boost::serialization::version_type) [with Archive = boost::archive::xml_iarchive; Matrix = Eigen::SparseMatrix<long int, 0, long int>; typename std::enable_if<std::is_convertible<Matrix*, Eigen::SparseMatrixBase<SparseDerived>*>::value, void>::type = void]’ /usr/include/boost/serialization/serialization.hpp:126:14: required from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = Eigen::SparseMatrix<long int, 0, long int>]’ /usr/include/boost/archive/detail/iserializer.hpp:188:40: required from ‘void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_iarchive; T = Eigen::SparseMatrix<long int, 0, long int>]’ /usr/include/boost/archive/detail/iserializer.hpp:120:1: required from ‘class boost::archive::detail::iserializer<boost::archive::xml_iarchive, Eigen::SparseMatrix<long int, 0, long int> >’ /usr/include/boost/archive/detail/iserializer.hpp:410:13: required from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::load_standard::invoke(Archive&, const T&) [with T = Eigen::SparseMatrix<long int, 0, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/iserializer.hpp:462:22: required from ‘static void boost::archive::detail::load_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = Eigen::SparseMatrix<long int, 0, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/iserializer.hpp:618:18: required from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::xml_iarchive; T = Eigen::SparseMatrix<long int, 0, long int>]’ /usr/include/boost/archive/detail/common_iarchive.hpp:66:22: required from ‘void boost::archive::detail::common_iarchive<Archive>::load_override(T&) [with T = Eigen::SparseMatrix<long int, 0, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/basic_xml_iarchive.hpp:78:9: required from ‘void boost::archive::basic_xml_iarchive<Archive>::load_override(const boost::serialization::nvp<T>&) [with T = Eigen::SparseMatrix<long int, 0, long int>; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/xml_iarchive.hpp:95:51: required from ‘void boost::archive::xml_iarchive_impl<Archive>::load_override(T&) [with T = const boost::serialization::nvp<Eigen::SparseMatrix<long int, 0, long int> >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/interface_iarchive.hpp:68:9: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = const boost::serialization::nvp<Eigen::SparseMatrix<long int, 0, long int> >; Archive = boost::archive::xml_iarchive]’ /usr/include/boost/archive/detail/interface_iarchive.hpp:75:32: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator&(T&) [with T = const boost::serialization::nvp<Eigen::SparseMatrix<long int, 0, long int> >; Archive = boost::archive::xml_iarchive]’ /home/matteo/Progetti/gadv/gadv-backend/logic/petri-net.cc:310:8: required from ‘void gadv::PetriNet::serialize(Archive&, unsigned int) [with Archive = boost::archive::xml_iarchive]’ /usr/include/boost/serialization/access.hpp:116:9: required from ‘static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = gadv::PetriNet]’ /usr/include/boost/serialization/serialization.hpp:68:22: required from ‘void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = gadv::PetriNet]’ /usr/include/boost/serialization/serialization.hpp:126:14: required from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_iarchive; T = gadv::PetriNet]’ /usr/include/boost/archive/detail/iserializer.hpp:188:40: required from ‘void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::xml_iarchive; T = gadv::PetriNet]’ /usr/include/boost/archive/detail/iserializer.hpp:120:1: required from ‘class boost::archive::detail::iserializer<boost::archive::xml_iarchive, gadv::PetriNet>’ /usr/include/boost/archive/detail/iserializer.hpp:369:31: required from ‘boost::archive::detail::pointer_iserializer<Archive, T>::pointer_iserializer() [with Archive = boost::archive::xml_iarchive; T = gadv::PetriNet]’ /usr/include/boost/serialization/singleton.hpp:100:7: required from ‘static T& boost::serialization::singleton<T>::get_instance() [with T = boost::archive::detail::pointer_iserializer<boost::archive::xml_iarchive, gadv::PetriNet>]’ /usr/include/boost/serialization/singleton.hpp:135:28: required from ‘static const T& boost::serialization::singleton<T>::get_const_instance() [with T = boost::archive::detail::pointer_iserializer<boost::archive::xml_iarchive, gadv::PetriNet>]’ /usr/include/boost/serialization/export.hpp:66:30: required from ‘static const boost::archive::detail::basic_pointer_iserializer& boost::archive::detail::export_impl<Archive, Serializable>::enable_load(mpl_::true_) [with Archive = boost::archive::xml_iarchive; Serializable = gadv::PetriNet; mpl_::true_ = mpl_::bool_<true>]’ /usr/include/boost/serialization/export.hpp:105:51: required from ‘static void boost::archive::detail::ptr_serialization_support<Archive, Serializable>::instantiate() [with Archive = boost::archive::xml_iarchive; Serializable = gadv::PetriNet]’ /usr/include/boost/serialization/export.hpp:86:1: required from ‘struct boost::archive::detail::ptr_serialization_support<boost::archive::xml_iarchive, gadv::PetriNet>’ /usr/include/boost/archive/detail/register_archive.hpp:25:8: required from ‘struct boost::archive::detail::_ptr_serialization_support<boost::archive::xml_iarchive, gadv::PetriNet>’ /usr/include/boost/archive/xml_iarchive.hpp:136:1: required by substitution of ‘template<class Serializable> typename boost::archive::detail::_ptr_serialization_support<boost::archive::xml_iarchive, Serializable>::type boost::archive::detail::instantiate_ptr_serialization(Serializable*, boost::archive::xml_iarchive*, boost::archive::detail::adl_tag) [with Serializable = gadv::PetriNet]’ /usr/include/boost/serialization/export.hpp:123:38: required from ‘void boost::archive::detail::extra_detail::guid_initializer<T>::export_guid(mpl_::false_) const [with T = gadv::PetriNet; mpl_::false_ = mpl_::bool_<false>]’ /usr/include/boost/serialization/export.hpp:133:20: required from ‘const boost::archive::detail::extra_detail::guid_initializer<T>& boost::archive::detail::extra_detail::guid_initializer<T>::export_guid() const [with T = gadv::PetriNet]’ /home/matteo/Progetti/gadv/gadv-backend/logic/petri-net.cc:47:1: required from here /usr/include/eigen3/Eigen/src/Core/NumTraits.h:103:59: error: invalid application of ‘sizeof’ to incomplete type ‘boost::serialization::U’ typename internal::conditional<sizeof(T)<=2, float, double>::type, // -----------------------------------------
Confirmed. I'll update a creduce'd testcase shortly.
Created attachment 44642 [details] creduce output Here's the result of many hours of creduction with this interestingness test: #!/bin/bash ~/src/llvm/latest/bin/clang++ -std=c++17 petri.cc -c -w || exit 1 LANG=C g++ -std=c++17 petri.cc -c -w 2>out && exit 1 awk "/ error: invalid application of 'sizeof' to incomplete type 'boost::serialization::U'/ { found=1 ; --errors } / error: / { ++errors } END { exit found ? errors : 99 }" out It compiles OK with clang but with g++ -std=c++17 -w the error is: petri-net.cc: In instantiation of 'struct a::e<boost::serialization::U>': petri-net.cc:44:50: required from 'class a::k<a::g<boost::serialization::U, 0, int> >' petri-net.cc:49:47: required from 'class a::g<boost::serialization::U, 0, int>' petri-net.cc:103:7: required from 'static void boost::serialization::bh<au, d>::bi(au) [with au = boost::cl; d = a::aa<a::g<int>, a::g<a::g<int>, 0, int> >]' petri-net.cc:109:3: required from 'void boost::serialization::bk(au, d, int) [with au = boost::cl; d = a::aa<a::g<int>, a::g<a::g<int>, 0, int> >]' petri-net.cc:148:5: [ skipping 32 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ] petri-net.cc:177:8: required from 'static void boost::cj<au>::ck::bi(au, d) [with d = a::g<int>; au = boost::cl]' petri-net.cc:182:11: required from 'static void boost::cj<au>::bi(au, d) [with d = a::g<int>; au = boost::cl]' petri-net.cc:188:9: required from 'void boost::bj(au, d) [with au = boost::cl; d = a::g<int>]' petri-net.cc:201:7: required from 'void boost::co::cn(d) [with d = a::g<int>]' petri-net.cc:208:5: required from 'void boost::cp::cn(boost::serialization::bd<d>) [with d = a::g<int>]' petri-net.cc:195:46: required from 'boost::cl& boost::interface_iarchive< <template-parameter-1-1> >::operator>>(d) [with d = boost::serialization::bd<a::g<int> >; <template-parameter-1-1> = int]' petri-net.cc:225:40: required from here petri-net.cc:37:15: error: invalid application of 'sizeof' to incomplete type 'boost::serialization::U' 37 | typename b< sizeof(d) >::type NonInteger; | ^~~~~~~~~ Bizarrely, it compiles OK if __attribute__((__used__)) is removed on line 167.
(In reply to Jonathan Wakely from comment #2) > Here's the result of many hours of creduction (and some manual reduction)
Further reduced: template < int > struct b { }; template < typename n > struct g { typedef b< sizeof(n) > l; }; template < typename h, typename = typename g< h >::l > class aa {}; template < typename h, typename bz > void bj(aa< h, bz >, int); template < template < class > class ct > void bj(ct< class U >); void f() { bj(aa<int>(), 0); } ---- (`__attribute__((__used__))` in the original example matters because it ensures that the call is instantiated.)
Hi, we encountered a the same bug. See: https://stackoverflow.com/questions/54534047/eigen-matrix-boostserialization-c17 The bug is reproducible with G++8. The bug seems to be related with the (new?) template argument deduction mechanism in G++7/8 with --std=c++17 (or --std=gnu++17). A simplified test case (thx @Marc Giese/SO), reproducing the problem just including Eigen without the boost dependency is attached (see below). // -------------------------------------------- // G++ 7 // -------------------------------------------- $ gcc -v Using built-in specs. COLLECT_GCC=gcc 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.3.0-27ubuntu1~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 --with-sysroot=/ --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.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04) // -------------------------------------------- // G++ 8 // -------------------------------------------- $ g++-8 -v Using built-in specs. COLLECT_GCC=g++-8 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.2.0-1ubuntu2~18.04' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --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 --with-sysroot=/ --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 8.2.0 (Ubuntu 8.2.0-1ubuntu2~18.04) // -------------------------------------------- // testcase (see: https://stackoverflow.com/a/54536756/1267320) // -------------------------------------------- #include <Eigen/Core> template<template<class U>class SPT>void f(SPT<class U>&); template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> void f(Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & arMatrix){}; int main() { Eigen::Matrix2d m; f(m); } // -------------------------------------------- compile with: (G++7 or G++8) g++ -std=c++17 main.cpp // -------------------------------------------- Error output: $ g++ -std=c++17 main.cpp In file included from /usr/local/include/Eigen/Core:365:0, from main.cpp:1: /usr/local/include/Eigen/src/Core/util/ForwardDeclarations.h: In instantiation of ‘struct Eigen::internal::accessors_level<U>’: main.cpp:9:8: recursively required by substitution of ‘template<template<class U> class SPT> void f(SPT<U>&) [with SPT = <missing>]’ main.cpp:9:8: required from here /usr/local/include/Eigen/src/Core/util/ForwardDeclarations.h:32:54: error: incomplete type ‘Eigen::internal::traits<U>’ used in nested name specifier enum { has_direct_access = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0, ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /usr/local/include/Eigen/src/Core/util/ForwardDeclarations.h:33:53: error: incomplete type ‘Eigen::internal::traits<U>’ used in nested name specifier has_write_access = (traits<Derived>::Flags & LvalueBit) ? 1 : 0, ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ // -------------------------------------------- // Preprocessed code // -------------------------------------------- compiled with: g++ -std=c++17 -E main.cpp > pp_main_minimal.ii See the attached pp_main_minimal.ii
Created attachment 45618 [details] Reduced test case with eigen-only dependency
Created attachment 45619 [details] Preprocessed test case with eigen-only dependency
Another case where someone hit this problem: https://stackoverflow.com/questions/54534047/eigen-matrix-boostserialization-c17/ Corresponding Bug at the Eigen-library: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1676
Independent of this issue, the forward declaration in boost/serialization/shared_ptr_helper.hpp does not make sense. I created a PR to fix that: https://github.com/boostorg/serialization/pull/144
I created a simplified example that has no dependencies at all: https://godbolt.org/z/uIy1Uu You can workaround the compilation issue by either: #1 - commenting line 16 and uncommenting line 15, i.e., by by-passing some indirection. #2 - commenting line 16 and uncommenting line 21, i.e., by removing the default value of the second templated parameter of Base<>. Hope it will help fixing the issue.
(In reply to ensadc from comment #4) > Further reduced: > > template < int > struct b { }; > template < typename n > struct g { > typedef b< sizeof(n) > l; > }; > template < typename h, typename = typename g< h >::l > class aa {}; > template < typename h, typename bz > > void bj(aa< h, bz >, int); > template < template < class > class ct > void bj(ct< class U >); > void f() { > bj(aa<int>(), 0); > } > ---- Hmm, it comes with -std=c++11 and -std=c++14 but not -std=c++17.
(In reply to Andrew Pinski from comment #11) > (In reply to ensadc from comment #4) > > Further reduced: > > > > template < int > struct b { }; > > template < typename n > struct g { > > typedef b< sizeof(n) > l; > > }; > > template < typename h, typename = typename g< h >::l > class aa {}; > > template < typename h, typename bz > > > void bj(aa< h, bz >, int); > > template < template < class > class ct > void bj(ct< class U >); > > void f() { > > bj(aa<int>(), 0); > > } > > ---- > > Hmm, it comes with -std=c++11 and -std=c++14 but not -std=c++17. Started to be rejected (with -std=c++17) since the introduction of -fnew-ttp-matching r7-5537-g31bfc9b9dd65ec
GCC 10 branch is being closed.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:155178ccb5f5bc89dcc8261ae1b64bc2fbfdbd45 commit r14-4109-g155178ccb5f5bc89dcc8261ae1b64bc2fbfdbd45 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Sep 18 14:41:05 2023 -0400 c++: always check arity before deduction This simple patch extends the r12-3271-gf1e73199569287 optimization to happen for deduction without explicit template arguments as well. The motivation for this is to accept testcases such as conv20.C and ttp40.C below, which don't use explicit template arguments but for which unnecessary template instantiation during deduction could be avoided if we uniformly pruned overloads according to arity early. This incidentally causes us to accept one reduced testcase from PR c++/84075, but the underlying issue there remains at large. As a nice side effect, this change causes the "candidate expects N argument(s)" note during overload resolution failure to point to the template candidate instead of the call site, which seems like an improvement along the lines of r14-309-g14e881eb030509. gcc/cp/ChangeLog: * call.cc (add_template_candidate_real): Check arity even when there are no explicit template arguments. Combine the two adjacent '!obj' tests into one. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/vt-57397-1.C: Expect "candidate expects ... N argument(s)" at the declaration site instead of the call site. * g++.dg/cpp0x/vt-57397-2.C: Likewise. * g++.dg/overload/template5.C: Likewise. * g++.dg/template/local6.C: Likewise. * g++.dg/template/conv20.C: New test. * g++.dg/template/ttp40.C: New test.