zeek/spicy

C++20 builds fail due to forward declarations/struct definition ordering

Closed this issue · 1 comments

I've been tinkering with moving the Zeek builds to C++20 now that we've kicked out a couple of the really old compilers. It's currently failing on the LDAP analyzer due to the order in which types are defined in the generated code. In C++17, it was valid to use forward-declared types in definitions for std::vector but C++20 is more strict about it. The specific error is:

In file included from /Users/tim/Desktop/projects/zeek-master/build/src/analyzer/protocol/ldap/ldap_ASN1.cc:6:
In file included from /Users/tim/Desktop/projects/zeek-master/auxil/spicy/hilti/runtime/include/hilti/rt/libhilti.h:9:
In file included from /Users/tim/Desktop/projects/zeek-master/build/auxil/spicy/include/hilti/rt/autogen/config.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/string:584:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__memory/allocator.h:130:58: error: invalid application of 'sizeof' to an incomplete type '__hlt_ldap::ASN1::ASN1Message'
            _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
                                                         ^~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__memory/allocator_traits.h:288:13: note: in instantiation of member function 'std::allocator<__hlt_ldap::ASN1::ASN1Message>::deallocate' requested here
        __a.deallocate(__p, __n);
            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/vector:491:29: note: in instantiation of member function 'std::allocator_traits<std::allocator<__hlt_ldap::ASN1::ASN1Message>>::deallocate' requested here
            __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/vector:500:67: note: in instantiation of member function 'std::vector<__hlt_ldap::ASN1::ASN1Message>::__destroy_vector::operator()' requested here
  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); }
                                                                  ^
/Users/tim/Desktop/projects/zeek-master/auxil/spicy/hilti/runtime/include/hilti/rt/types/vector.h:279:5: note: in instantiation of member function 'std::vector<__hlt_ldap::ASN1::ASN1Message>::~vector' requested here
    ~Vector() = default;
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/optional:305:21: note: in defaulted destructor for 'hilti::rt::Vector<__hlt_ldap::ASN1::ASN1Message>' first required here
            __val_.~value_type();
                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/optional:379:8: note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
struct __optional_storage_base : __optional_destruct_base<_Tp>
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/optional:586:5: note: in defaulted default constructor for 'std::__optional_copy_base<hilti::rt::Vector<__hlt_ldap::ASN1::ASN1Message>>' first required here
    __optional_move_base() = default;
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/optional:618:5: note: in defaulted default constructor for 'std::__optional_move_base<hilti::rt::Vector<__hlt_ldap::ASN1::ASN1Message>>' first required here
    __optional_copy_assign_base() = default;
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/optional:651:5: note: in defaulted default constructor for 'std::__optional_copy_assign_base<hilti::rt::Vector<__hlt_ldap::ASN1::ASN1Message>>' first required here
    __optional_move_assign_base() = default;
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/optional:800:41: note: in defaulted default constructor for 'std::__optional_move_assign_base<hilti::rt::Vector<__hlt_ldap::ASN1::ASN1Message>>' first required here
    _LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {}
                                        ^
/Users/tim/Desktop/projects/zeek-master/build/src/analyzer/protocol/ldap/ldap_ASN1.cc:225:68: note: in instantiation of member function 'std::optional<hilti::rt::Vector<__hlt_ldap::ASN1::ASN1Message>>::optional' requested here
        std::optional<::hilti::rt::Vector<ASN1Message>> submessages{};
                                                                   ^
/Users/tim/Desktop/projects/zeek-master/build/src/analyzer/protocol/ldap/ldap_ASN1.cc:13:12: note: forward declaration of '__hlt_ldap::ASN1::ASN1Message'
    struct ASN1Message;
           ^

Reordering the struct definitions in ldap_ASN1.cc so that ASN1Message comes before ASN1Submessages fixes the error.

If you want to test against a Zeek build, I have everything necessary to do so on the topic/timw/c++20 branch.

I wouldn't make C++20 support a goal currently, so closing for now.