C++11 code gen bug for enums with default values

rascalDanrascalDan Dan GoodliffeOrganization: PersonalProject: C++ object serializationMember

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

  • xdmxdm La Coruña, SpainJose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice DeveloperAdministrators, ZeroC Staff ZeroC Staff

    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é

  • rascalDanrascalDan Dan GoodliffeOrganization: PersonalProject: C++ object serializationMember

    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

  • xdmxdm La Coruña, SpainJose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice DeveloperAdministrators, ZeroC Staff ZeroC Staff

    What compiler and operating systems are you using?

  • rascalDanrascalDan Dan GoodliffeOrganization: PersonalProject: C++ object serializationMember

    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

    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'
    
  • xdmxdm La Coruña, SpainJose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice DeveloperAdministrators, ZeroC Staff ZeroC Staff

    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

  • rascalDanrascalDan Dan GoodliffeOrganization: PersonalProject: C++ object serializationMember

    Ah ha. I've applied those patches to libmcpp and everything is working great now.

    Thanks for your time, José.

Sign In or Register to comment.