[jdk11u-dev] RFR: 8324307: [11u] hotspot fails to build with GCC 12 and newer (non-static data member initializers)
Andrew John Hughes
andrew at openjdk.org
Mon Feb 12 21:40:13 UTC 2024
On Wed, 31 Jan 2024 08:10:11 GMT, Goetz Lindenmaier <goetz at openjdk.org> wrote:
>> GCC 12 and newer warn about non-static data member initialisers when operating under -std=gnu++98 (jdk11u-dev's C++ standards version). These warnings are promoted to errors by default.
>>
>> This is an issue for jdk11u-dev which uses the C++ standard version '-std=gnu++98'. It is not an issue for later JDK versions which have moved to newer standards (JEP 347 moved JDK16 to -std=c++14): therefore an 11u-specific fix is required.
>>
>> The approach used in this PR is to remove the initialisers, in common with what we did when backporting the same code to jdk8u-dev.
>
> Removing the tag in the meantime
> Hi @GoeLin ,
>
> > @jmtd, if these initializers are not needed at all, shouldn't they be removed in the higher releases as well?
>
> This is a really good question and I took some time to ponder my reply.
>
> They are not needed from a computational POV because the relevant fields are all initialised in the object constructors in all cases. However, to know this I had to read through the class definition to be sure. I didn't write the original code but if I had I would have likely also preferred an explicit null initialisation in the member declaration, which makes clear the intent that we do not have uninitialised fields and do not risk reading from uninitialised fields. There's a chance the constructor could be altered later and an iniitialisation accidentally removed, or an alternative constructor added lacking the initialisation, etc.
>
> I doubt that anyone would welcome a patch to remove the redundant initialisers in main, but I could propose one if you disagree. WDYT?
I would say this is the sort of change that belongs only in 11u and older, for compatibility reasons (old C/C++ standards, older compilers). The current code in 17u+ is fine with `-std=c++14`.
Incidentally, if we are fixing 11u to compile with GCC 12, should we not also enable a GHA build with GCC 12 in a separate PR so that it does not regress again?
-------------
PR Comment: https://git.openjdk.org/jdk11u-dev/pull/2470#issuecomment-1939627192
More information about the jdk-updates-dev
mailing list