Stefan Glienke 2002 Posted March 24, 2021 Please vote if you think the compiler could help us writing more robust code: https://quality.embarcadero.com/browse/RSP-33504 4 Share this post Link to post
Rollo62 536 Posted March 25, 2021 I think Marcos proposal to change the projects default settings would be a possible solution (workaround) Quote With {$WARN UNSAFE_CAST ON} the lines ==> [dcc32 Warning] Unit47.pas(31): W1048 Unsafe typecast of 'TObject' to 'Pointer' Share this post Link to post
Fritzew 51 Posted March 25, 2021 Look at this: program Project20; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TVectorD3 = record x, y, z: Double; end; TDirection = type TVectorD3; {$WARN UNSAFE_CAST ON} procedure Test; var V: TVectorD3; D: TDirection; begin V := default (TVectorD3); D := TDirection(V); end; begin try Test; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. Will also produce a Warning. So if you enable UNSAFE_CAST there will be a lot of Warnings. And every place surround with a {$WARN UNSAFE_CAST OFF} is a bad Idea But I'm with Stefan here. A new Warning for Pointer Assignment would be fine. 1 Share this post Link to post
Stefan Glienke 2002 Posted March 25, 2021 (edited) Search for UNSAFE_CAST in QP and you'll find some issues that report all the bogus this produces - maybe after fixing those it might be somewhat usable. If that can avoid introducing yet a new warning type - I am all for that option. Edited March 25, 2021 by Stefan Glienke 1 Share this post Link to post