ZeroC

Archived

This forum has been archived. Please start a new discussion on GitHub.

GCC warnings in slice-generated code

joshmoore
joshmoore Germany
In an effort to remove all the compiler warnings for OMERO.cpp, it was necessary to disable several types of GCC warnings for the code generated by slice2cpp:
  • -Wno-switch-default
  • -Wno-redundant-decls
  • -Wno-overloaded-virtual
  • -Wno-old-style-cast
  • -Wno-deprecated-declarations

This was done on the one hand by using cmake's set_source_files_properties to disable the warnings during the compilation of the generated .cpp files themselves and on the other by intoducing a IceNoWarnPush header which must be included before all includes of generated header files.

Support either in slice2cpp or via compiler flags would be appreciated to help reduce these warnings. A sampling of the errors is below.

Cheers,
~Josh
/opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/api/Gateway.cpp: In member function ‘Ice::DispatchStatus omero::api::Gateway::___keepAlive(IceInternal::Incoming&, const Ice::Current&)’:
/opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/api/Gateway.cpp:9852:28: error: ‘virtual void omero::api::Gateway::keepAlive(const Ice::Current&)’ is deprecated (declared at /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/api/Gateway.h:5474) [-Werror=deprecated-declarations]
         keepAlive(__current);
In file included from /opt/Ice-3.5.1/include/IceUtil/ThreadException.h:14:0,
                 from /opt/Ice-3.5.1/include/IceUtil/Lock.h:14,
                 from /opt/Ice-3.5.1/include/IceUtil/Mutex.h:14,
                 from /opt/Ice-3.5.1/include/Ice/Proxy.h:14,
                 from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.h:29,
                 from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.cpp:21:
/opt/Ice-3.5.1/include/IceUtil/Time.h: In member function ‘double IceUtil::Time::operator/(const IceUtil::Time&) const’:
/opt/Ice-3.5.1/include/IceUtil/Time.h:117:24: error: use of old-style cast [-Werror=old-style-cast]
         return (double)_usec / (double)rhs._usec;
                        ^
/opt/Ice-3.5.1/include/IceUtil/Time.h:117:44: error: use of old-style cast [-Werror=old-style-cast]
         return (double)_usec / (double)rhs._usec;
In file included from /opt/Ice-3.5.1/include/Ice/BasicStream.h:14:0,
                 from /opt/Ice-3.5.1/include/Ice/OutgoingAsync.h:24,
                 from /opt/Ice-3.5.1/include/Ice/Proxy.h:25,
                 from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.h:29,
                 from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.cpp:21:
/opt/Ice-3.5.1/include/Ice/Object.h:124:18: error: ‘virtual void Ice::Object::__readImpl(const InputStreamPtr&)’ was hidden [-Werror=overloaded-virtual]
     virtual void __readImpl(const InputStreamPtr&);
                  ^
In file included from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.cpp:21:0:
/opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.h:4084:18: error:   by ‘virtual void omero::RType::__readImpl(IceInternal::BasicStream*)’ [-Werror=overloaded-virtual]
     virtual void __readImpl(::IceInternal::BasicStream*);
                  ^
In file included from /opt/Ice-3.5.1/include/Ice/BasicStream.h:16:0,
                 from /opt/Ice-3.5.1/include/Ice/OutgoingAsync.h:24,
                 from /opt/Ice-3.5.1/include/Ice/Proxy.h:25,
                 from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.h:29,
                 from /opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.cpp:21:
/opt/Ice-3.5.1/include/Ice/ObjectFactoryF.h:59:29: error: previous declaration of ‘Ice::LocalObject* Ice::upCast(Ice::ObjectFactory*)’ [-Werror=redundant-decls]
 ICE_API ::Ice::LocalObject* upCast(::Ice::ObjectFactory*);
                             ^
/opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.cpp: In member function ‘virtual Ice::DispatchStatus omero::RMap::__dispatch(IceInternal::Incoming&, const Ice::Current&)’:
/opt/ome1/components/tools/OmeroCpp/cppbuild/components/tools/OmeroCpp/gen/omero/RTypes.cpp:5746:11: error: switch missing default case [-Werror=switch-default]
     switch(r.first - __omero__RMap_all)
           ^

Comments

  • bernard
    bernard Jupiter, FL
    Hi Josh,

    Thank you for this report. We will definitely fix some of these, for example, the C-style in a header is clearly an oversight.

    With GCC, we currently use -Wall -Werror when building Ice (+ tests and demos). Which flag(s) do you use to get these additional warnings?

    Best regards,
    Bernard
  • rleigh
    rleigh
    Our currently used set of flags is:
    -Wall
          -Wcast-align
          -Wcast-qual
          -Wctor-dtor-privacy
          -Wextra
          -Wformat=2
          -Wimplicit-atomic-properties
          -Wmissing-declarations
          -Wnon-virtual-dtor
          -Wold-style-cast
          -Woverlength-strings
          -Woverloaded-virtual
          -Wredundant-decls
          -Wreorder
          -Wswitch-default
          -Wunused-variable
          -Wwrite-strings
          -fstrict-aliasing
    

    The following are also used routinely, but can be disabled with cmake (due to the larger number of warnings in third-party headers):
    -Wconversion
          -Wdocumentation
          -Wfloat-equal
          -Wmissing-prototypes
          -Wunreachable-code
    

    The main GCC-specific version difference we encounter is on "switch(enum)" which triggers -Wswitch-default if it lacks a default case, but isn't needed due to covering all available enumerations in existing cases. If you add a default case, you then get unreachable code warnings. For this specific case we wrap the function contining the switch with
    #ifdef __GNUC__
    #  pragma GCC diagnostic push
    #  pragma GCC diagnostic ignored "-Wswitch-default"
    #endif
    
    <function>
    
    #ifdef __GNUC__
    #  pragma GCC diagnostic pop
    #endif
    

    which allows other (non-enum) switch statements to benefit from -Wswitch-default checking. Other than this exception to the rule, we make sure our code is clean for all of the above warnings. If the slice2cpp-generated code could also be made clean, this would be greatly beneficial for ourselves and all other users who build with strict warnings.

    Kind regards,
    Roger Leigh
  • rleigh
    rleigh
    Compiler checks

    Just FYI, this is our current use of these flags:

    https://github.com/openmicroscopy/bioformats/blob/develop/cpp/cmake/CompilerChecks.cmake
  • rleigh
    rleigh
    MSVC compiler flags

    I should also note that for Windows builds, having the generated Ice headers generate zero warnings with cl /W3 and /W4 would also be highly desirable.