Bug 53129

Summary: Wself-assign
Product: gcc Reporter: Manuel López-Ibáñez <manu>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: egallager, lcwu
Priority: P3 Keywords: diagnostic, easyhack, patch
Version: 7.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87387
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91225
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105237
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2016-08-22 00:00:00
Bug Depends on:    
Bug Blocks: 87403    

Description Manuel López-Ibáñez 2012-04-26 18:08:30 UTC
void func()
{
  int i = 2;
  int x = 0;   /* warn */
  float f = 5.0;
  double a[3];

  i = i + 0;   /* not warn */
  f = f / 1;   /* not warn */
  a[1] = a[1]; /* warn */
  i += 0;      /* not warn */
  x = x;      /* warn */
}

manuel@gcc12:~$ clang -fsyntax-only -Wself-assign wselfassign.c
wselfassign.c:12:5: warning: explicitly assigning a variable of type 'int' to itself [-Wself-assign]
  x = x;      /* warn */
  ~ ^ ~
1 warning generated.

An implementation was submitted to GCC but never approved here:

http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02390.html
Comment 1 Manuel López-Ibáñez 2012-04-26 18:12:52 UTC
Hi Le-Chun, I still think GCC wants this warning. Are you planning to submit a new patch in the near future?
Comment 2 Eric Gallager 2016-08-22 13:29:33 UTC
I'd like to see this warning added, too... can I mark this as confirmed?
Comment 3 Manuel López-Ibáñez 2016-08-22 13:45:38 UTC
Usually one does not confirm their own PRs, but in this case it seems obvious and given you request...
Comment 4 Eric Gallager 2018-01-27 19:38:27 UTC
(In reply to Manuel López-Ibáñez from comment #0)
> 
> An implementation was submitted to GCC but never approved here:
> 
> http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02390.html

Adding the "patch" keyword