Hello,
I have this trivial script to remove useless casts to self:
@ disable drop_cast @
type T;
T E;
@@
- (T)
E
It works but I'm hitting false positives when the code casts away
qualifiers for field types. Please see the attached test case:
- Good: Cast is kept in foo()
- Bad: Cast is dropped in baz()
Applying the generated diff will lead to a gcc warning:
$ gcc -c qualifier.c
qualifier.c: In function ‘baz’:
qualifier.c:12:12: warning: return discards ‘const’ qualifier from
pointer target type [-Wdiscarded-qualifiers]
return &b->i;
^~~~~
I tried disabling the optional_qualifier iso but that has no effect:
- Not needed for the foo() case
- No effect for the baz() case
I even tried prepending an alternation with "const T good;" but the cast
still gets removed.
thanks
bye
michael
int *foo(const int *i)
{
return (int *)i;
}
struct bar {
int i;
};
int *baz(const struct bar *b)
{
return (int *)&b->i;
}
@ disable drop_cast @
type T;
T E;
@@
- (T)
E
qualifier.res
Description: chemical/shelx
_______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
