facebook/fbthrift

compilation error in "clang & libstdc++-12.1 & c++20"

alex-700 opened this issue · 1 comments

Hello, fbthrift team!

  • The code generated for metadata.thrift is not compiling in "clang-14 & libstdc++-12.1 & c++20" environment. The version of clang isn't important, but version of libstdc++ and cxx_standard are.
  • The problem can be seen in the snippet. The copy-ctor of vector<ThriftConstValuePair> inside set_cvmap can't be instantiated before definition of ThriftConstValuePair. And a compiler, IMHO, can make a decision to instantiate it eagerly in instantiation point at the end of ThriftConstValue definition. So, IIYC, the generated code is "ill-formed no diagnostic required".
  • I don't see a simple solution, but can suggest several hard ones:
    • Member methods in such "cyclic" cases (or even always) can be declared inside the class, but defined later after definition of all classes.
    • All classes can be put into some struct X (like last-level namespace), which will enforce standard-compliant compilers postpone instantiation to the end of X definition.

@alex-700 Would you verify whether this in fact solves the problem you encountered?