cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Removing the last return statement from a void function
@ 2021-03-18 18:26 Thomas Adam
  2021-03-18 19:24 ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Adam @ 2021-03-18 18:26 UTC (permalink / raw)
  To: Coccinelle

Hello all,

I've another Coccinelle question I'm hoping you can help me with.  The
codebase I'm working on is old, and has some interesting styles which
by themselves probably don't cause any problems, but newer C compilers
are now starting to flag them.

In particular, there seems to be a pattern in this code base of using
explicit `return;` statements at the end of void functions.  Here's an
example:

static void broadcast_mini_icon(FvwmWindow *fw)
{
    if (!FMiniIconsSupported)
    {
        return;
    }
    if (fw->mini_pixmap_file && fw->mini_icon)
    {
        BroadcastFvwmPicture( M_MINI_ICON, FW_W(fw),
            FW_W_FRAME(fw), (unsigned long)fw,
            fw->mini_icon, fw->mini_pixmap_file);
    }
    return;
}

Here you can see the last return statement is not necessary.

I'm trying to make coccinelle recognise this and remove such cases.
Here's what I've tried:

@@
identifier f;
@@

void f(...) {
  <...
- return;
...>

}

... which sort of works, but proceeds to remove *all* `return;`
statements from void functions, rather than the last occurance in the
function.

Am I on the right track with this approach, or do I need to do
something more creative?

Thanks once more for your help.

Thomas
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-19 21:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 18:26 [Cocci] Removing the last return statement from a void function Thomas Adam
2021-03-18 19:24 ` Julia Lawall
2021-03-19 20:40   ` Thomas Adam
2021-03-19 21:10     ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).