cornelius / libkode

C++ code generation library
8 stars 11 forks source link

Generate static members initializers into the declaration #49

Open martonmiklos opened 2 years ago

martonmiklos commented 2 years ago

Hello David,

I quite like doing the member initialization in the declaration rather than in the constructor. I created a change which allows me to do this in the libkode generated codes.

Before review I would like to hear your opinion on this one: can we go ahead and enforce this behavior generally or shall I create an optional configuration for it? If the later I will work on it, if you have no objection please review my change. Thanks!

martonmiklos commented 2 years ago

Ah my remembering capabilities are quite bad: we started to discuss this in the #37 , so please review this change :)

dfaure-kdab commented 2 years ago

I certainly like the idea of generating C++-11 code, including initialization in header files. But I have a few concerns/questions:

  1. Doesn't this commit remove initialization of non-static members altogether? I wish libkode had more extensive autotests such as actually generating code and comparing it with reference files... (like KDE's kconfig_compiler autotests)
  2. Doesn't it also remove the type? decl += formatType(v.type()); is gone.
  3. Any reason why you only do this for static members and not for all types of members? On the other hand, (for both static and non-static) I'm worried about the case where the initializer is a function call that requires including another header. But that's rare I suppose.