aloberoger wrote:pending an improvement or fixation or something else, it seems appropriate to point out this as a mistake
Unfortunate that there was no test for this in our test suite, otherwise probably would have noticed this source code compatibility break. The CONST versus CAST issue has been an on-going source of complication.
- we have the CONST specifier, where we promise not to modify data, and we would like the compiler to let us know if we break that promise.
- we have the CAST operator, where we change the data's type, possibly invoking conversion procedures, and we may or may not want to be warn/error on unsafe casting.
For concept, we probably want something like:
- ForceCast() - perform the cast and warn/error nothing
- SafeCast() - perform the cast with all type check warnings and errors
- Cast() - perform the cast, maybe with a few warnings only.
For comparison, standard c++ has it's own operators for this concept of selectively allowing or warning/error on casting: static_cast, reinterpret_cast, const_cast, and dynamic_cast. And MS has c++ extension safe_cast.
My efforts on const/cast in fbc-1.06 were to try and fix the really serious bugs, and then enable warnings only with '-w constness'. Obviously this change, and the bug as reported in the earlier post slipped through.
Another thought is maybe to have cast() allow const-ness change only, or data type change only, without warning/error. But if both are changed at same time through a single cast(), maybe give the programmer a warning.