Skip to content

Failed to compile for struct with constructors which have more than 1 arguments #31

Description

@Yikai-Liao

The following 3 cases could pass compile

struct Foo1 {
    int data;
};

struct Foo2 {
    int data;
    Foo2() = default;
};

struct Foo3 {
    int data;
    Foo3(const int data): data{data} {}
};

But once the constructor accepts more than one arugments, we will get an error, like this:

struct Foo4 {
    int data;
    Foo4() = default; // with or without it just lead to the same error
    Foo4(const int data, const bool bar): data{data} {}
}
FAILED: CMakeFiles/symusic.dir/src/io/alpaca.cpp.obj 
C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1438~1.331\bin\Hostx64\x64\cl.exe  /nologo /TP -DFMT_HEADER_ONLY=1 -IC:\Users\nhy\symusic-libra\include -IC:\Users\nhy\symusic-libra\3rdparty\minimidi\include -IC:\Users\nhy\symusic-libra\3rdparty\pdqsort -IC:\Users\nhy\symusic-libra\3rdparty\zpp_bits -IC:\Users\nhy\symusic-libra\3rdparty\fmt\include -IC:\Users\nhy\symusic-libra\3rdparty\alpaca\include /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++20 -MDd /GL -bigobj /showIncludes /FoCMakeFiles\symusic.dir\src\io\alpaca.cpp.obj /FdCMakeFiles\symusic.dir\symusic.pdb /FS -c C:\Users\nhy\symusic-libra\src\io\alpaca.cpp
C:\Users\nhy\symusic-libra\3rdparty\alpaca\include\alpaca/detail/struct_nth_field.h(21): error C3448: the number of identifiers must match the number of array elements or members in a structured binding declaration
C:\Users\nhy\symusic-libra\3rdparty\alpaca\include\alpaca/detail/struct_nth_field.h(21): note: the template instantiation context (the oldest one first) is
C:\Users\nhy\symusic-libra\src\io\alpaca.cpp(104): note: see reference to function template instantiation 'std::vector<uint8_t,std::allocator<uint8_t>> symusic::details::serailize_alpaca<symusic::Foo4>(const symusic::Foo4 &)' being compiled
C:\Users\nhy\symusic-libra\src\io\alpaca.cpp(29): note: see reference to function template instantiation 'size_t alpaca::serialize<T,2,std::vector<uint8_t,std::allocator<uint8_t>>>(const T &,Container &)' being compiled
        with
        [
            T=symusic::Foo4,
            Container=std::vector<uint8_t,std::allocator<uint8_t>>
        ]
C:\Users\nhy\symusic-libra\3rdparty\alpaca\include\alpaca/alpaca.h(152): note: see reference to function template instantiation 'void alpaca::detail::serialize_helper<alpaca::options::none,T,2,std::vector<uint8_t,std::allocator<uint8_t>>,0>(const T &,Container &,size_t &)' being compiled
        with
        [
            T=symusic::Foo4,
            Container=std::vector<uint8_t,std::allocator<uint8_t>>
        ]
C:\Users\nhy\symusic-libra\3rdparty\alpaca\include\alpaca/alpaca.h(135): note: see reference to function template instantiation 'decltype(auto) alpaca::detail::get<0,const T&,2>(type) noexcept' being compiled
        with
        [
            T=symusic::Foo4,
            type=const symusic::Foo4 &
        ]
ninja: build stopped: subcommand failed.

Note that I'm using c++20 and msvc 19.38.33133.0 on windows11. And I have read the similar issue #24

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions