microsoft / bond

Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services.
MIT License
2.61k stars 321 forks source link

Bond generated headers don't work for clang in c++20 #1176

Open tiagomacarios opened 1 year ago

tiagomacarios commented 1 year ago

Bond generates code as follows: https://godbolt.org/z/a4qnbcjeh

#include <vector>

struct forward_decl;

struct S{
    std::vector <forward_decl> m;

    S(){};
};

struct forward_decl{};

But this does not work in C++20 (in clang) because the constructor will be instantiated with the forward declaration and compilation will fail.

A possible fix is to move the constructor body until after all entities have bee fully defined: https://godbolt.org/z/6YjarYx3c

#include <vector>

struct forward_decl;

struct S {
    std::vector<forward_decl> m;

    S();
};

struct forward_decl {};

inline S::S() {}

Office is currently hitting this when trying to update to C++20.

chwarr commented 1 year ago

This change makes sense and should be backward compatible to C++11 as well. Feel free to submit a PR with the changes to code generation.

Does S::S() {} need to be marked inline as it won't be inside a class definition?

tiagomacarios commented 1 year ago

yes it will need inline. I am not familiar with Haskell, nor do I have an environment set. I presume this is a simple change, could you author it? This is currently blocking us. If you prefer I can create an internal bug on you team - just provide me the correct area path.