Bug 53129 - Wself-assign
Summary: Wself-assign
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, easyhack, patch
Depends on:
Blocks:
 
Reported: 2012-04-26 18:08 UTC by Manuel López-Ibáñez
Modified: 2018-01-27 19:38 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-08-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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