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

User-Defined Types not work with MSVC 2022?! #25

Open
An0nyMooUS opened this issue Dec 15, 2021 · 2 comments
Open

User-Defined Types not work with MSVC 2022?! #25

An0nyMooUS opened this issue Dec 15, 2021 · 2 comments

Comments

@An0nyMooUS
Copy link

An0nyMooUS commented Dec 15, 2021

namespace example {
    struct Person {
        std::string name;
        std::uint32_t age_years;
        std::uint8_t height_inches;
        std::uint16_t weight_pounds;
        NOP_STRUCTURE(Person, name, age_years, height_inches, weight_pounds);
    };
}  // namespace example

int main(int argc, char** argv) {
    using Writer = nop::StreamWriter<std::stringstream>;
    nop::Serializer<Writer> serializer;

    serializer.Write(example::Person{ "John Doe", 37, 72, 180 });
    serializer.Write(std::vector<example::Person>{
        {"John Doe", 37, 72, 180}, { "Jane Doe", 36, 69, 130 }});

    const std::string data = serializer.writer().stream().str();
    std::cout << "Wrote " << data.size() << " bytes." << std::endl;

    // [write to file]
    std::ofstream saveFile("e.bin", std::ios::binary);
    saveFile.write(data.c_str(), data.size());
    saveFile.flush();
    saveFile.close();

    return 0;
}

MSVC 2022 Result:
Wrote 8 bytes.
image
Warnings

  • warning C4003: not enough arguments for function-like macro invocation '_NOP_FIRST_ARG'
  • warning C4003: not enough arguments for function-like macro invocation '_NOP_REST_ARG'

CLANG LLVM Result:
Wrote 50 bytes.
image

why this not working with MSVC 2022?!

@themarpe
Copy link

+1 seeing similar issue.
@XXxR4GALXxx I suspect this is because of MSVC non conforming preprocessor, which treats __VA_ARGS__ differently.

One idea I have, which you may try out is setting the /Zc:preprocessor flag - let me know if that works for you.

CC: @eieio any help/idea on making this work with MSVC as well by default? (nlohmann json seems to handle it with their macros, maybe could be taken as an inspiration?)

@themarpe
Copy link

Could be handled gracefully by #24 if we add a PUBLIC /Zc:preprocessor (or /experimental:preprocessor, depending on MSVC version) compile options flag.
IMO best way to do it, no further changes required and MSVCs conformance is getting better and better over time

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