CodingStyle: compound literals
There are two big questions here:
I don't really know about the first question. If I had to guess, I'd assume most problems with that will have been solved or worked-around by now, given that compound literals have been in use for years now.
Re: the second question – as far as I can tell without purchasing the official standards document from ISO, compound literal initialization works the same as struct initialization (1), where omitted members are zero-initialized (2), and zero-initialized pointers are set to appropriate null pointers (3), so the answer would be "yes".
I suspect those uses that exist are relatively new code? While the CodingStyle has not said anything against them, I've believed that their use is to be avoided for compatibility reasons. Some research on their support should be done. Especially if Visual Studio now supports them, and what is the first version that does.
It's also possible that we end allowing their use in specific contexts, e.g., if some compiler implements them partially. Like tcc does vararrays (which we may have not properly documented, the thing just came up recently when we had to revert strict compiler vararrays compliance check to one that checks just the specific case that freeciv uses).
Reply To alienvalkyrie
Reply To cazfi
I suspect those uses that exist are relatively new code?
Almost eight years old; first introduced in what is now commit 0076666
Existed in 2.6 stable series, and nobody has complained.
Reply To cazfi
Existed in 2.6 stable series, and nobody has complained.
Does that mean we're going forward with officially allowing them? If so, should we add appropriate configure checks? (And by "we" I mean "you", because I have no clue how those work.)
I still don't know if latest version of Visual Studio supports them or not. Whether that's relevant is another question. Will there ever be anyone making it possible to build freeciv with Visual Studio? (This might have the usual answer: I've ordered a new Windows laptop for making windows builds)
Yes, if we are going to allow them, we should add configure checks, at least for the autotools builds, maybe also for the meson builds.
Reply To cazfi
I still don't know if latest version of Visual Studio supports them or not.
Apparently, based on answers I got from people I asked, the Microsoft Visual C++ compiler supports compound literals in C mode since MSVC 2013 (source). (It does not seem to support compound literals in C++ mode.)
So that sounds like a "yes", assuming the distinction between "C mode" and "C++ mode" doesn't need to happen on a project level, but on a compilation unit level.
Whether that's relevant is another question.
I'd argue that when push comes to shove, code readability should be considered more important than compatibility with a proprietary development environment. There would certainly be upsides to supporting VS, but I don't think they're greater than the upsides of being able to declare and initialize a struct that's only used in one place in the place it's used.
Reply To alienvalkyrie
supports compound literals in C mode since MSVC 2013 (source).
Note: According to that source, designated initialization (which is already used in plenty of places, e.g. to initialize universals and citizen governor presets) is also only supported since MSVC 2013; so if I'm reading this correctly (again, depending on the mode distinction thing from above), using compound literals wouldn't make our code any less MSVC-compatible than it was before.
Please write the CodingStyle patch, and open ticket about the configure check.
Continued from #43809.
Compound literals (which look similar to struct/unition initializers) are currently only used in very few places (most prominently, the requirement_fulfilled_by_* macros in common/requirements.h). We need to figure out / decide if and how we generally want to use them, and add that information to doc/CodingStyle.