C++ Bindings Generate static const Code that will not Compile



Why does ORBit2 generated a static const char * data member of a class, which will not compile with gcc 3.2?

I received an IDL file from a partner that contains statements like the following IDL file:

//Source file: C:/Docs/Netfires/cf-idl/cf.idl

#ifndef __CF_DEFINED
#define __CF_DEFINED

/* CmIdentification
  %X% %Q% %Z% %W% */

module CF {

        interface FileSystem {
                const string SIZE = "SIZE";
        };

};

#endif

When I compiled this file with the ORBit2 IDL compiler it generated the cf-cpp-common.h file with the following code fragment:

namespace CF
{
typedef ::CF::FileSystem* FileSystem_ptr;
typedef ::_orbitcpp::ObjectPtr_var<FileSystem> FileSystem_var;
typedef FileSystem_var FileSystem_mgr;
typedef ::_orbitcpp::ObjectPtr_out<FileSystem> FileSystem_out;
typedef FileSystem_ptr FileSystemRef;

class FileSystem : public virtual CORBA::Object
 {
public:
        typedef ::CF::FileSystem_mgr value_t;
        typedef CF_FileSystem c_value_t;
        static void pack_elem (const value_t &cpp_elem, c_value_t &c_elem);
        static void unpack_elem (value_t &cpp_elem, const c_value_t &c_elem);
#undef SIZE
        static  const char *SIZE = "SIZE";

The C++ standard states that it is legal to initialize static const data members in a class that are enumerated or integral types.

The C++ Standard ISO/IEC 14882:1998(E) on page 158 states: “If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression.”

Since the generated statement is not of integral nor enumeration type, this statement generates the following errors when compiled by gcc 3.2:

gcc -c -g -DORBIT2=1 -D_REENTRANT -I/home/nfr/local/include/orbit-2.0 -I/home/nfr/local/include/linc-1.0 -I/home/nfr/local/include/glib-2.0 -I/home/nfr/local/lib/glib-2.0/include -I/home/nfr/local/include/orbitcpp-2.0 client.cc
In file included from cf-cpp-stubs.h:11,
                 from client.cc:3:
cf-cpp-common.h:46: invalid in-class initialization of static data member of 
   non-integral type `const char*'

Is the syntax of the IDL file incorrect? If it is correct, then why does ORBit2 generated C++ code that will not compile?

Regards,
Larry S. Gustafson






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]