[Cocci] Initialization thrown away

Julia Lawall julia.lawall at lip6.fr
Thu Dec 11 07:37:43 CET 2014


> @@
> identifier i;
> @@
> -int i;
> +long i;
>
> Applied to a file containing:
>
> int a=20;
>
> Results in:
>
> diff =
> --- initializer_ignored.c
> +++ /tmp/cocci-output-19589-137add-initializer_ignored.c
> @@ -1 +1 @@
> -int a=20;
> +long a;
>
> I was expecting the =20; to be preserved, or at least that it just doesn't
> match unless I specify a separate case where I explicitly declare a constant
> metavariable and check for the case where the variable is initialized with a
> constant.

This is not at all the intended behavior.  It may be relted to recent
changes allowing the above to match things like int a, b, c;

As a temporary workaround, it seems that if one rewrites the
transformation as follows, then it has the desirable behavior of keeping
the = 20:

- int a
+ long a
  ;

julia


More information about the Cocci mailing list