Using g++ version 4.0.3

Hello everyone.

Since I'm using Arch Linux distribution, and I have gcc 4.0.3 as default C/C++ compiler,
I went into a bunc of problems compiling OpenCASCSADE library. Most of the compilation
errors was trigerred by missuses of copy constructors instead of copy operators and the
const correctness. Beside that I have found some memory leaks produced when someone
decided to avoid compiler error messages by using local memory allocation, but without
proper dealocation.

I decided to correct all of them and to modify the source files until compilation went
smoothly. Finally I did it.

First of all, I decided not to expose private constructors, but instead I opted to use
copy operators. So I replaced (for example):



  TopTools_ListOfShape tmpListOfShape;

That's way I forced the compiler to use copy operator, as expected by the author.

Second, the most of the errors was related to incorrect use of const keyword,
especially const char* pointers.

For example, in the inc/Standard_TypeDef.hxx was the declaration:

typedef char* Standard_CString;

All around the code there was the const Standard_CString declarations.
But, instead of const char*, compiler interpreted it as char const*.

Consider the following code:

typedef char* StringType;

class Options
  Options(const StringType var) {}

int main()
    const char* cPtr = "Pero";

    Options o(cPtr);

    return 0;

Compilation gives:

g++ -o proba In function ‘int main()’: error: invalid conversion from ‘const char*’ to ‘char*’ error:   initializing argument 1 of ‘Options::Options(char*)’

So I decided to replace typedef with #define statement. I know, it was not an ideal
solution, but it was the quickest one I could remember.

All in all, I have prepared the patch with all the corrections I've made so, if
someone wish to apply it and investigate, the patch can be downloaded from:

Please note that the patch is created against local cvs repo, and the repository is my
local disk at: /radni/cvsroot. So, in order to be applied, it should be edited using
the sed editor and every occurrence of /radni/cvsroot should be replaced with some other
cvs repo.

I didn't notice any strange behaviour in DRAWEXE as well as in FreeCAD application,
that was built on top of OC code, but my testing was not so thorough so I can't
claim that I haven't introduce any other error.

I can only hope that my contribution will be usefull for the comunity.

Regards, Berni.

P.S. You can reach me at but, please, put the [OC]
at the front of the subject so I can be sure that my spam filter won't vanish
your message.

John Brown's picture

Err... All wrong!
'const char*' is functionally equivalent to 'char const*' (pointer to char type, which can't be changed via this pointer).

It's NOT 'const char*', but 'const StringType'

John Brown's picture

To clarify:
it's const TYPE, so
'char* const' == const TYPE (from right: TYPE const -> char* const), NOT 'char const*'/'const char*'

Sorry for OT.

Bernard Čupić's picture

Not completely wrong!

Compiler interpret declaration of 'const StringType' as 'char* const' which is
functionally different to what one expect: 'const char*'.

So it is not 'char const*' but 'char* const'. But, anyway, compiler won't compile original code as expected. I don't know how this code has compiled even on earlier
version of g++ since I can't get it to compile either using gcc 3.3.2 or Sun C++ 5.8

I can't verify this code with MS compilers on Win platform since I don't use it.