On Saturday, 12 September 2020 at 11:43:03 UTC, MoonlightSentinel
wrote:
Currently looking into enabling it by default but it showed an
interesting side effect. The frontend can now conclude that a
== b is always true if a and b are instances of an empty struct
(without custom opEquals).
This caused "unreachable code" warnings for VariantN in Phobos
and could probably affect other projects as well.
How many improvements does this warning have to block before we
decide its value for the language is net-negative?
GCC doesn't have it. [1] Clang has it, but only if you
specifically ask for it with -Wunreachable-code; it's not part of
-Wall or -Wextra. [2] Rust has it, but lets you turn it off with
an annotation. [3] Java has it, but it explicitly does *not* take
constant-folding into account. [4]
The only language I could find that follows D's approach is C#
[5], and C#'s generics don't get a separate semantic analysis for
each concrete type like D's templates do.
[1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
[2]
https://clang.llvm.org/docs/DiagnosticsReference.html#wunreachable-code
[3]
https://doc.rust-lang.org/rust-by-example/attribute/unused.html
[4]
https://docs.oracle.com/javase/specs/jls/se14/html/jls-14.html#jls-14.22
[5] https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0162