C++11 code gen bug for enums with default values
Hi all,
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
Comments
Hi Dan,
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?
Best Regards,
José
Hi José,
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.
Thanks,
Dan
What compiler and operating systems are you using?
Gentoo, gcc-7.3.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
That is because gentoo libmcpp is missing a patch required to build Ice, see my pull request here https://github.com/gentoo/gentoo/pull/7820
Ah ha. I've applied those patches to libmcpp and everything is working great now.
Thanks for your time, José.