getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
900 stars 76 forks source link

Link error with -fsanitize=undefined #16

Closed ecatmur closed 8 months ago

ecatmur commented 8 months ago

The following program fails to link on g++ 13.2.0 x86-64 Linux (Ubuntu):

#include <rfl/internal/get_field_names.hpp>
struct A { int i; };
int main() { rfl::internal::get_field_names<A>(); }

error:

/tmp/ccKMlHON.o:a.cpp:function auto get_field_names<A>():(.text._Z15get_field_namesI1AEDav+0x5): error: undefined reference to 'fake_object<A>'
collect2: error: ld returned 1 exit status

might be related to #15 reduced: https://godbolt.org/z/1jecWY947

possible workaround is to use [[gnu::no_sanitize_undefined]]

liuzicheng1987 commented 8 months ago

@ecatmur I see that you have already forked the repo and implemented a fix. Cool stuff. Thank you very much. I will integrate this tonight!

liuzicheng1987 commented 8 months ago

@ecatmur , I was able to reproduce the issue and I can confirm that your proposed solution fixes it.

Here is what I have done:

Sorry I didn't merge your PR, but it would very likely have created merge conflicts with the f/msvc branch that I had opened in parallel (and that is now merged as well).

That being said, thank you very much for your issue and your contribution. This is exactly what open source should be all about.