Forbid needless pointer casts

Andre Pany andre at s-e-a-p.de
Thu Feb 20 11:37:29 UTC 2020


On Thursday, 20 February 2020 at 11:31:17 UTC, FlameInHeart wrote:
> Hey,
>
> How about forbidding this:
>
> void foo(Monkey* m) {
>     Monkey* m2 = cast(Monkey*) m;
> }
>
> Pointer casts are potentially nasty when refactoring and the 
> needless ones are easy for the compiler to detect, and probably 
> no-one will find objections to this change.
>
> Just an easy win, isn't it?
>
> (not going to write a DIP for this...)

There is also the possibility to add this check to DScanner 
instead of the compiler.
By the way, DScanner is now also easily accessible from Dub.
You can just say `dub lint` and it will check your current dub 
package.

Kind regards
André


More information about the Digitalmars-d mailing list