www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Add -wnan switch to flag default NaN initializations

reply Walter Bright <newshound2 digitalmars.com> writes:
https://github.com/dlang/dmd/pull/23663
Aug 20
next sibling parent reply ABrightLight <example example.com> writes:
On Friday, 21 August 2026 at 06:26:36 UTC, Walter Bright wrote:
 https://github.com/dlang/dmd/pull/23663
I really like this solution. Thank you Walter
Aug 21
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 8/21/2026 12:02 AM, ABrightLight wrote:
 I really like this solution. Thank you Walter
You're welcome. I had the idea when I was out for a jog this morning, and wondered why I hadn't thought of it before.
Aug 21
next sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 21/08/2026 7:22 PM, Walter Bright wrote:
 On 8/21/2026 12:02 AM, ABrightLight wrote:
 I really like this solution. Thank you Walter
You're welcome. I had the idea when I was out for a jog this morning, and wondered why I hadn't thought of it before.
I suspect it may be for a similar reason as to why I had not mentioned it. -vtls for instance, is for something quite intractable, it is from symbol resolution. Default initialization, is generally a syntax level feature and is easily seen. They don't serve the same purpose, although they may appear the same on the surface. Also nobody has asked for the ability to audit the locations where this exists, like they did for TLS.
Aug 21
parent reply Alexandru Ermicioi <alexandru.ermicioi gmail.com> writes:
On Friday, 21 August 2026 at 08:03:46 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 They don't serve the same purpose, although they may appear the 
 same on the surface.

 Also nobody has asked for the ability to audit the locations 
 where this exists, like they did for TLS.
Still a bit better, than nothing right?
Aug 21
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 21/08/2026 8:06 PM, Alexandru Ermicioi wrote:
 On Friday, 21 August 2026 at 08:03:46 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 They don't serve the same purpose, although they may appear the same 
 on the surface.

 Also nobody has asked for the ability to audit the locations where 
 this exists, like they did for TLS.
Still a bit better, than nothing right?
Not exactly: https://dlang.org/changelog/2.113.0.html#dmd.fastdfa.uninitialized The switch could be useful in tracking down default init, but it won't help you if you write float.nan some place, or is in library code that the compiler isn't seeing. Each of these solutions has their own tradeoffs, and neither is perfect. Its a good feature, but what I have classified as a low value one.
Aug 21
prev sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Friday, 21 August 2026 at 07:22:29 UTC, Walter Bright wrote:
 wondered why I hadn't thought of it before.
Surely its been suggested for years If your finally convinced its time to resolve the float mess; theres going to be dozens of little details and it should be a package deal. see: https://github.com/dlang/dmd/issues/23666#issuecomment-5372588419 there will be dozens of these if you open the debate in earnest *IF* the goal is to keep float.nan and have a flag that errors out for team 0; fine, but you should define the stable "number-y" api so it becomes tractable to write terse templates https://forum.dlang.org/post/obkghamdrvjibmxrfktg forum.dlang.org
Aug 21
prev sibling next sibling parent claptrap <clap trap.com> writes:
On Friday, 21 August 2026 at 06:26:36 UTC, Walter Bright wrote:
 https://github.com/dlang/dmd/pull/23663
I know i've been arguing that zero init is not as much of an issue as people think, but Im also aware that it'll never change, too much hassle for little (very subjective) benefit for only some people. So this is a pretty good solution.
Aug 21
prev sibling next sibling parent Kapendev <alexandroskapretsos gmail.com> writes:
On Friday, 21 August 2026 at 06:26:36 UTC, Walter Bright wrote:
 https://github.com/dlang/dmd/pull/23663
Looks good.
Aug 21
prev sibling parent GB <gb542 gmail.com> writes:
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.
Aug 22