Bug 17626 – Same name variable assignment should raise a compile-time warning

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-09T12:13:39Z
Last change time
2018-04-26T05:01:54Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
David Baum
See also
https://issues.dlang.org/show_bug.cgi?id=11970

Comments

Comment #0 by david — 2017-07-09T12:13:39Z
Comment #1 by david — 2017-07-09T12:31:43Z
I would like to suggest having the following code raise a compile-time warning: ``` x = x; ``` Other than invoking the copy constructor, this is a no-op. I had the following piece of code, which for "some reason" didn't work: ``` struct FuncPtr{ void* ptr; this(void* ptr){ ptr = ptr; } ... } ``` Locating this wasn't immediate, and I don't see valid reasons for someone to purposely write such a code. I suggest at least raising a compile-time warning. Much easier than to hunt for nulls in runtime.
Comment #2 by greeenify — 2017-07-09T12:59:14Z
You probably have better chances of getting this into DScanner: https://github.com/dlang-community/D-Scanner/issues/497
Comment #3 by david — 2017-07-09T13:01:58Z
@greenify -- thanks for the DScanner issue. I really appreciate it.
Comment #4 by greensunny12 — 2018-04-03T01:52:30Z
I agree that this is a very common error. Let's try to get it in DMD first: https://github.com/dlang/dmd/pull/8119
Comment #5 by slavo5150 — 2018-04-25T09:47:16Z
*** This issue has been marked as a duplicate of issue 11970 ***