Add -wnan switch to flag default NaN initializations

GB gb542 at gmail.com
Sun Aug 23 02:50:10 UTC 2026


On Friday, 21 August 2026 at 06:26:36 UTC, Walter Bright wrote:
> https://github.com/dlang/dmd/pull/23663

I think this is a very useful switch because it allows you to 
audit existing code for places where the default value is being 
relied upon.

But it only applies to NaN ??

What is really needed, is a stronger invariant that provides a 
persistent compile-time state - which is something -wnan cannot 
do.

Two features could however complement each other.

-wnan
Audit/default-initialization diagnostic
"Tell me where the program is relying on default NaN."

@UNASSIGNED (or perhaps @mustAssign since D already has @mustUse)
Semantic safety contract:
"For this variable, default initialization is deliberately not 
considered sufficient. Prove that an explicit assignment occurred 
before every read."
Useful for new code or particularly important variables.

So... fine...keep whatever default initialization Walter wants. 
Just give programmers a way to say that the default doesn't count 
as an explicitly established value.



More information about the Digitalmars-d mailing list