Bug 12789 – Add -transition=nan to emit floating-point variables default-initialized to NaN

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-23T13:51:00Z
Last change time
2014-05-24T20:25:39Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2014-05-23T13:51:51Z
C and C++ do not use NaN, but instead zero-initialize floating-point variables (e.g. in struct fields). When porting or interfacing to such libraries it becomes very easy to forget this and to have odd results at runtime due to D's use of default-initialization to NaN. I propose introducing a -transition=nan flag which will emit the location of all the floating-point variables which are default-initialized to NaN.
Comment #1 by andrej.mitrovich — 2014-05-23T13:57:45Z
Comment #2 by bearophile_hugs — 2014-05-23T14:21:45Z
I suggest something better: a compiler switch like "-fromc" that helps porting C/C++ code to D. Such flag warns against NaNs, about large fixed-size variables passed by value, and cases like this that have a different meaning in C and D: int *x, y; And related matters.
Comment #3 by bearophile_hugs — 2014-05-23T14:22:44Z
>about large fixed-size variables I meant fixed-size arrays.
Comment #4 by andrej.mitrovich — 2014-05-23T14:28:37Z
(In reply to bearophile_hugs from comment #2) > I suggest something better: a compiler switch like "-fromc" that helps > porting C/C++ code to D. Such flag warns against NaNs, about large > fixed-size variables passed by value, and cases like this that have a > different meaning in C and D: > > int *x, y; > > And related matters. I think we added `-transition` specifically to allow fine-grained control of these diagnostics. You can always add support to a build tool like DUB where --fromC would pass in things like a hypothetical "-transition=carrays", "-transition=cpointers", etc.
Comment #5 by bearophile_hugs — 2014-05-23T14:32:45Z
(In reply to Andrej Mitrovic from comment #4) > I think we added `-transition` specifically to allow fine-grained control of > these diagnostics. Right, sorry, I forgot.
Comment #6 by bugzilla — 2014-05-24T20:25:39Z
As mentioned in the pull request, issues like these are properly in the domain of a lint-like utility, not the compiler.