This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Add a new warning flag -Wself-assign


On 29/05/2010 00:47, Le-Chun Wu wrote:

  Hello,

> This patch adds a new warnings flag "-Wself-assign" that warns about
> self-assignment (including self-initialization). This warning is
> intended for detecting accidental self-assignment due to typos, and
> therefore does not warn on a statement that is semantically a
> self-assignment after constant folding. Here is an example of what
> will trigger a self-assign warning and what will not:
> 
>           void func()
>           {
>              int i = 2;
>              int x = x;   /* 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 */
>           }

  It is a very common idiom to write:

> <returntype> f (<type> x)
> {
>   x = x;
>   [ ... do other stuff ... ]
>   return [some value or none]
> }

... in order try and avoid parameter-unused warnings in a portable fashion;
how does your patch react to this technique?

    cheers,
      DaveK


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]