C++ compiler issues with generated code (original) (raw)

Firstly thank you for providing this code as open source.

I have found some issues with the C++ generated code:

  1. Some methods taking no parameters use (void). That is not standard C++
  2. SBE_CONSTEXPR is sometimes followed by const for integer types. That's not legal C++ when SBE_CONSTEXPR is defined as constexpr
  3. SBE_CONSTEXPR is sometimes followed by char *. That's not legal C++ when SBE_CONSTEXPR is defined as constexpr as a constexpr may not return a char *, it must return a const char *.
  4. The code generated for method wrapForEncode to check if the count is in bounds "if (count < %5$d || count > %6$d)" is illegal when the minimum is the minimum for the type or the maximum is the maximum for the type or both. A #pragma GCC diagnostic ignored "-Wtautological-compare" directive would resolve this but see next.
  5. The #pragma GCC diagnostic ignored "-Wtautological-compare" directive is not valid for gcc (at least not with gcc 5.4.0. It seems to be ok with clang 3.7.
  6. The C style casts should be replaced by static_casts and reinterpret_casts. Though I note that you have specifically stated this is meant to generate C++98 code.
  7. The generated headers have extension of .h. That is no longer the preferred extension for C++ header files.

I have forked your code and added a C++11 generator (C11Generator.java) which fixes the above, but it would be more widely beneficial if it was co-ordinated with your CppGenerator.

Happy to discuss further.

Thank you
Dany