Hi,

I wanted to write a small cocci patch to transform
static const char *str = "...";
into
static const char * const str = "...";

I used the following semantic patch:

@@
identifier str;
expression E;
@@
-static const char *str
+static const char * const str
    = E;

But coccinelle reports an error when running it:

Fatal error: exception Failure("plus: parse error:
 = File "const_char_const.cocci", line 6, column 21,  charpos = 77
    around = 'const', whole content = +static const char * const s
")


So I did some more experimentation and it looks as if coccinelle does not
like type qualifiers anywhere else except before the type. E.g. in C "const
T" and "T const" are both legal C and have the same meaning. But coccinelle
only accepts the first variant. Coccinelle's C parser though seems to be
aware of it, since

@@
identifier p;
@@
*const void *p;

matches both 'const void *foo;' and  'void const *bar;'. Also 'const void *
const batz;' is matched. What does not match is 'volatile const void *foo;'
although I would expect it to match unless 'disable optional_qualifier' is
given for the rule.     

Also specifying multiple qualifiers does not seem work.
E.g. "const volatile void *p" or even "const const void *p"


I'm using 1.0.0-rc14.

Thanks,
- Lars
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to