C++11 code gen bug for enums with default values
I've stumbled across a problem with the header file generated by slice2cpp (3.7.0, but having tracked the problem still present in 3.7.1-rc1)
Given an Ice enumeration, a C++ enum class is created, all is well.
Given an Ice class containing an instance of that enumeration with a default value, the generated constructor is incorrect. Specifically, the field initialiser is missing the enumeration name as required by enum class.
I've looked at the code (
slice2cpp/Gen.cpp) and it appears that none of the calls to
writeDataMemberInitializers set the
cpp11 flag, which defaults to false. I have a patch which addresses this, setting it false in all cases expect for
Slice::Gen::Cpp11LocalObjectVisitor::visitClassDefStart, which sets it to true. This fixes the problem I have, but I wouldn't claim my testing is comprehensive. I can post the patch for review if desired.
Thanks for reporting this issue, I have push a patch to our 3.7 branch, can you test that and confirm it solves your problem?
Thanks for the fix. I'm struggling to build HEAD of the 3.7 branch (unrelated,
IceStormInternal.ice:22: module name 'IceStorm' must differ from the name of its immediately enclosing module)
But I can and have built slice2cpp and used that to generate code for my own project and can confirm your patch fixes the enum class problem.
What compiler and operating systems are you using?0
I've just run git bisect between v3.7.0 and HEAD of branch 3.7, building srcs in cpp.
The first failing commit is f1565f0f13b88c1ab04fb66aff67e9ac443af8ac
Compiling ../cpp/src/IceGrid/Internal.ice Compiling ../slice/IceLocatorDiscovery/IceLocatorDiscovery.ice Compiling ../cpp/src/IceStorm/Election.ice Compiling ../cpp/src/IceStorm/IceStormInternal.ice Compiling ../cpp/src/IceStorm/Instrumentation.ice Compiling ../cpp/src/IceStorm/LinkRecord.ice /home/randomdan/dev/Ice/cpp/src/IceStorm/Election.ice:308: syntax error /home/randomdan/dev/Ice/slice/Ice/Current.ice:118: `Identity' is not defined /home/randomdan/dev/Ice/cpp/src/IceStorm/IceStormInternal.ice:22: module name `IceStorm' must differ from the name of its immediately enclosing module /home/randomdan/dev/Ice/cpp/src/IceStorm/IceStormInternal.ice:125: syntax error make: *** [Makefile:33: src/IceStorm/generated/IceStormInternal.cpp] Error 1 make: *** Waiting for unfinished jobs.... make: *** [Makefile:33: src/IceStorm/generated/Election.cpp] Error 1 /home/randomdan/dev/Ice/slice/Ice/Current.ice:118: `Identity' is not defined /home/randomdan/dev/Ice/cpp/src/IceStorm/IceStormInternal.ice:22: module name `IceStorm' must differ from the name of its immediately enclosing module /home/randomdan/dev/Ice/cpp/src/IceStorm/LinkRecord.ice:17: module name `IceStorm' must differ from the name of its immediately enclosing module /home/randomdan/dev/Ice/cpp/src/IceStorm/LinkRecord.ice:30: struct `LinkRecord' must have at least one member /home/randomdan/dev/Ice/cpp/src/IceStorm/LinkRecord.ice:33: syntax error make: *** [Makefile:33: src/IceStorm/generated/LinkRecord.cpp] Error 1 make: Leaving directory '/home/randomdan/dev/Ice/cpp'0
That is because gentoo libmcpp is missing a patch required to build Ice, see my pull request here https://github.com/gentoo/gentoo/pull/78200
Ah ha. I've applied those patches to libmcpp and everything is working great now.
Thanks for your time, José.0