Bug 11943 – Emit warning for default initialized pointers

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-17T18:53:23Z
Last change time
2023-06-22T10:42:02Z
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2014-01-17T18:53:23Z
Consider: class C { ... } void foo() { C c; // warning: c is default initialized to null. If that is // intended, write it as C c = null; C d = null; // no warning int* p; // warning ... int* q = null; // no warning } Of course, this won't eliminate null pointers. But it would put a dent in the inadvertancy of them.
Comment #1 by yebblies — 2014-01-17T20:51:38Z
Oh hell no. Isn't this exactly the kind of useless false-positive warning you're usually against? This would be at home in a lint tool, but IMO has no place as a compiler warning.
Comment #2 by bearophile_hugs — 2014-01-18T03:55:07Z
I think this is a bad idea, and it doesn't solve the the intended problem, beside having other problems. Weren't you against warnings? Instead I suggest you to do this (in this order): 1) Go read 5 or 10 good recent research papers on this topic; 2) Go look at how 3 or 4 recently designed languages already solve this problem; 3) Go in the D newsgroup, present your proposed solution and discuss it with people; 4) Write a DIP, discuss it and try to remove all its corner cases and difficult situations; 5) Try to implement it, offer it as experimental solution (with some compiler switch? A pragma?), and collect usage opinions from people. 6) Fix and improve the design and implementation. 7) If all is OK, make it a permanent feature of the language, otherwise remove it from the compiler.
Comment #3 by dfj1esp02 — 2014-01-18T10:52:43Z
(In reply to comment #2) > 2) Go look at how 3 or 4 recently designed languages already solve this > problem; I like the C# approach, but it uses flow analysis.
Comment #4 by bugzilla — 2014-01-18T11:52:33Z
> Weren't you against warnings? Not as a path towards deprecation and eventually making it an error.
Comment #5 by bearophile_hugs — 2014-01-18T14:57:44Z
(In reply to comment #4) > > Weren't you against warnings? > > Not as a path towards deprecation and eventually making it an error. You fuss about even tiny breaking changes of my my enhancement requests, and now are you suggesting to eventually turn this into an error? int* p; I see no evidence that this whole idea will improve the situation. And how do you initialize dynamic arrays of pointers/references? auto arr = new int*[10]; I suggest to read some updated research papers on the whole topic (about F*, and other from Microsoft Research), and look at how other modern languages solve this problem.
Comment #6 by pro.mathias.lang — 2018-10-19T05:21:39Z
@Walter: I think your stance on warnings might have evolved over the years. As discussed in this thread, false positive are terrible, and not something we want. Shall we close this as WONTFIX ?