niXman / yas

Yet Another Serialization
731 stars 95 forks source link

Build error when serializing std::variant to JSON #108

Closed GIGte closed 2 years ago

GIGte commented 2 years ago

std::size_t is used in the JSON serialization of std::variant. See this line: https://github.com/niXman/yas/blob/cba47df0a91393d3e9a269792710ab50a9b51375/include/yas/types/std/variant.hpp#L129 yas tries to serialize std::size_t as yas::object, and this fails to build on macOS. The problem is for both saving and loading.

niXman commented 2 years ago

hi,

unfortunately I have no macOS and you didn't provide me an error message. so should I just add #include <cstdint> ?

GIGte commented 2 years ago

$ clang++ main.cpp -Iyas-master/include -std=c++17

#include <yas/serialize.hpp>
#include <yas/std_types.hpp>

int main() {
    std::variant<int> v{0};
    auto buf = yas::save<yas::mem | yas::json>(v);

    return 0;
}

errors.txt

It works when I replace std::size_t idx with std::uint8_t idx.

I think this is related to https://github.com/niXman/yas/issues/79#issuecomment-932990242

niXman commented 2 years ago

ah, got it! thanks! will fix it soon!

niXman commented 2 years ago

done: https://github.com/niXman/yas/commit/74f631061da84ddbfd8a9b1df6603642c1412bfd

please test and report.

GIGte commented 2 years ago

Builds now, thanks!