DMD 2.057 and 2.058head void main(){ class X{} X x; static assert(!__traits(compiles, cast(int)x));// assertion failure int y = cast(int)x; // compile error } Apparently casts are checked for validity too late.
This happens because only some checking of casts is done in the frontend, the rest is done in the glue layer. (e2ir.c CastExp::toElem)
Inverse of issue 11485 https://github.com/D-Programming-Language/dmd/pull/2886
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d930042fdf0bba5ec43191a9d625264693075732 Fix Issue 7472 - Cast from class to basic type not rejected during semantic https://github.com/D-Programming-Language/dmd/commit/d5d9624f1e629aab1500330bb0891eef554dc9fe Merge pull request #2886 from yebblies/issue7472 Issue 7472 - Cast from class to basic type not rejected during semantic
Commits pushed to 2.065 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d930042fdf0bba5ec43191a9d625264693075732 Fix Issue 7472 - Cast from class to basic type not rejected during semantic https://github.com/D-Programming-Language/dmd/commit/d5d9624f1e629aab1500330bb0891eef554dc9fe Merge pull request #2886 from yebblies/issue7472