Compare commits

...

2 Commits

Author SHA1 Message Date
Ondřej Surý
540914a8be Fix the only occurrence of using void function as argument to return() 2019-12-06 13:37:20 +01:00
Ondřej Surý
d956c12961 Add semantic patch to find void f() { ... return ((void)g())); ... }
When a function returns void, it can be used as an argument to return in
function returning also void, e.g.:

void in(void) {
  return;
}

void out(void) {
  return (in());
}

while this is legal, it should be rewritten as:

void out(void) {
  in();
  return;
}

The semantic patch just find the occurrences, and they need to be fixed
by hand.
2019-12-06 13:37:20 +01:00
2 changed files with 21 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
@ rule1 @
identifier f1;
@@
void f1(...)
{
...
}
@ rule2 @
identifier rule1.f1;
identifier f2;
@@
void f2(...) {
...
* return(f1(...));
...
}

View File

@@ -1022,7 +1022,8 @@ cfg_print_duration(cfg_printer_t *pctx, const cfg_obj_t *obj) {
/* If this is not an ISO 8601 duration, just print it as a number. */
if (!duration.iso8601) {
return (cfg_print_rawuint(pctx, duration.parts[6]));
cfg_print_rawuint(pctx, duration.parts[6]);
return;
}
/* Calculate length of string. */