[omniORB] Compiler warnings (casting from const char* to char* and vice ver sa)

Matej Kenda matej.kenda@hermes.si
Fri, 14 Dec 2001 11:07:58 +0100


Hi,

We are using omniORB 3.0.4 in our application. We have turned on many
detailed compiler warnings to warn us about potential problems in our code.

When a omniidl generated header file is included, we get a bunch of warnings
about casting. For instance:

/proj/omni/include/omniORB3/stringtypes.h: In method
`_CORBA_String_member::_CORBA_String_member ()':
/proj/matejk/ivdcvs/ivd-3rdparty/omni/include/omniORB3/stringtypes.h:190:
warning: cast from `const char *const' to `char *' discards qualifiers from
pointer target type

/proj/omni/include/omniORB3/CORBA.h: In method
`CORBA::Any::from_string::from_string (const char *, long unsigned int,
bool)': /proj/matejk/ivdcvs/ivd-3rdparty/omni/include/omniORB3/CORBA.h:426:
warning: cast from `const char *' to `char *' discards qualifiers from
pointer target type

I've checked the code (stringtypes.h:190) and in my opinion the warnings
would go away if C++ const_cast would be used instead of C-style cast.


Are there any special reasons, why the C-style cast is used?


Best regards,

Matej


P.S.: We have no problems with omniORB. It works as expected. It is just
hard to spot a real problem if too many warnings fly over the screen.


== Original (3.0.4):

  inline _CORBA_String_member()
    : _ptr((char*) omni::empty_string) {}

== Corrected

  inline _CORBA_String_member()
    : _ptr(const_cast<char*> omni::empty_string) {}