Menu

#601 Uncrustify 0.60 drops semicolons after array compound literals

0.61
fixed
semicolon (2)
C
5
2014-09-11
2014-09-10
No

This arose out of the code in http://stackoverflow.com/q/25718838 and specifically answer http://stackoverflow.com/a/25719284.

Reduced to nearly the minimum, the macros generated the code:

void deallocate2(S **s_ptr)
{
    { void *stopper_for_apply = (int[]){0}; void **list_for_apply = (void *[]){(*s_ptr)->arr, *s_ptr, stopper_for_apply}; for (int i = 0; list_for_apply[i] != stopper_for_apply; i++) { saferFree((void *) & (list_for_apply[i])); } };
}

When I run that code through Uncrustify 0.60, the output is missing two semicolons, one after each of the array literals:

void deallocate2(S **s_ptr)
{
    {
        void *stopper_for_apply = (int[]){
            0
        }  void **list_for_apply = (void *[]){
            (*s_ptr)->arr, *s_ptr, stopper_for_apply
        }  for (int i = 0; list_for_apply[i] != stopper_for_apply; i++)
        {
            saferFree((void *) &(list_for_apply[i]));
        }
    }
}

The semicolons are in the original but not in the uncrustify output (so the previously valid code is made invalid by reformatting). The output should be more like:

void deallocate2(S **s_ptr)
{
    {
        void *stopper_for_apply = (int[]){ 0 };
        void **list_for_apply = (void *[]){
            (*s_ptr)->arr, *s_ptr, stopper_for_apply
        };
        for (int i = 0; list_for_apply[i] != stopper_for_apply; i++)
        {
            saferFree((void *) &(list_for_apply[i]));
        }
    }
}

I can certainly supply my uncrustify.cfg file if you need it. I'm not worried about layout formatting (where newlines and braces etc appear); I'm simply worried that compilable code became uncompilable.

Discussion

  • Ben Gardner

    Ben Gardner - 2014-09-11
    • labels: --> semicolon
    • status: open --> fixed
    • assigned_to: Ben Gardner
    • Group: Future --> 0.61
     
  • Ben Gardner

    Ben Gardner - 2014-09-11

    Should now be fixed in git.

     

    Last edit: Ben Gardner 2014-09-11
  • Jonathan Leffler

    Thank you. That was swiftly fixed.

     
MongoDB Logo MongoDB