[Issue 24520] [REG] C-style casts are now accepted (sometimes)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 24 11:22:03 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24520

timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr at gmx.ch

--- Comment #2 from timon.gehr at gmx.ch ---
https://issues.dlang.org/show_bug.cgi?id=24025

As Steven says:

> An alternative to delaying the C style cast to semantic is to just remove the error.
>
> If a cast from C is desired, then it will work if the type can be constructed with that parameter.
>
> Back when this error was created, something like `int(5)` was not valid code. Now it is. So most cases of casting will just have a failed implicit cast error.
>
> Ironically, this error *hurts* porting C code, instead of helping.

Therefore, I believe the change in behavior with "casts" is intentional.

(int)(c % 8) is just treated as another way to write int(c % 8). Similar to how
`(f)(1, 2)` just means `f(1, 2)`.

I do appreciate that grammar changes make it harder to write code that is
compatible with multiple compiler versions, but I also think testing with
different compiler versions cannot be avoided if one wants to support them.

--


More information about the Digitalmars-d-bugs mailing list