Skip to content

Incorrect macro expansions #331

@KoenigKrote

Description

@KoenigKrote

Invalid semicolons get inserted when using certain define macros.

For example, the well known do { stuff; } while (0) macro wrapper trick expands incorrectly.'

Example:

#define foo(x) do { return (x); } while (0)

int f(int num)
{
  if (num > 0)
    foo(num);
  else
    return num * num;
}

Expands into

int f(int num)
{
  if(num > 0) do {
    return (num);
  } while(0);
  
  ;
  else return num * num; 
}

Which has incorrectly inserted an additional semicolon between the if/else blocks (or automatically inserted one after while(0), causing the original semicolon to be pushed between blocks)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions