Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Yikai-Liao opened this issue Dec 30, 2023 · 1 comment

Comments

@Yikai-Liao
Copy link

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

@xgdgsc
Copy link

xgdgsc commented Jan 26, 2024

I also get similar error with Clang 11 and GCC 9 on linux like

 /data/include/alpaca/detail/struct_nth_field.h:14:11: error: type 'const hos::xs::Sk<float>' decomposes into 6 elements, but only 1 names were provided
[build]     auto &[p1] = value;

The only 1 names part would change to only 2 names if I change the constructor from 1 argument to 2 arguments. The struct Sk has 6 members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants