(Build -CW) Static cast error in CW11

1620479

Jan 20 1997 1:25PM


CodeWarrior can no longer compile MacApp. It compiled with their previous release, but as of CW11 (version 1.7 compiler), it will no longer compile. There errors I get are with PascalString.h, and here is the first of 20: Error : illegal explicit conversion from 'CCharStr *' to 'char *' PascalString.h line 175 { return MAstatic_cast(char*, this); } [snip]
Steps to reproduce problem: 
All you have to do is try to compile App.

Workaround: 
I made the following change in the MAConditionalMacros.h:

// Some compilers don't have new style casting yet.
//
// If your compiler supports these casts then go ahead and use the direct casting operators
// in your own code.
//
/*#if defined(__MWERKS__)
#	define MAstatic_cast(TYPE, EXPR)			static_cast(EXPR)
#	define MAconst_cast(TYPE, EXPR)				const_cast(EXPR)
#	define MAreinterpret_cast(TYPE, EXPR)		reinterpret_cast(EXPR)
#else*/
#	define MAstatic_cast(TYPE, EXPR)			((TYPE)(EXPR))
#	define MAconst_cast(TYPE, EXPR)				((TYPE)(EXPR))
#	define MAreinterpret_cast(TYPE, EXPR)		((TYPE)(EXPR))
/* #endif */

> Has anyone besides me had trouble building MacApp R12 with CodeWarrior 11?
> It appears that static_cast is broken in CW11, which MacApp uses in its
> MAstatic_cast #define when building with Metrowerks.
Actually, static_cast is now broken differently than it used to be. In CW10 and earlier it would let you do all kinds of nasty illegal things you should have to use reinterpret_cast for, like casting void* to int*. MacApp (and others) unwittingly took advantage of this bug to generate lots of incorrect code that just happened to work under CW10. This bug is fixed in CW11, which reveals where MacApp is broken, especially the string classes. The bad news is the static_cast now doesn't appear to notice cast operators when considering wether it's legal to static_cast a class to something else - this used to work in CW10. MacApp also gets bitten by this - they have code which is correct but now fails to compile - the string classes come to mind again.
Fix:

We are now using Codewarrior 12 (CWPro 1) and the native xxx_cast operators. This is no longer a problem.