LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 26229 - google-readability-braces-around-statements creates invalid code with macros around statement needing braces
Summary: google-readability-braces-around-statements creates invalid code with macros ...
Status: NEW
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-21 01:07 PST by Richard
Modified: 2016-01-21 01:30 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard 2016-01-21 01:07:14 PST
Given the following code:

extern void foo();
extern void bar();

void f(int i) {
  if (i > 0)
#ifdef FOO
    foo();
#else
    bar();
#endif
}


google-readability-braces-around-statements places the braces incorrectly:

extern void foo();
extern void bar();

void f(int i) {
  if (i > 0) {
#ifdef FOO
    foo();
#else
    bar();
  }
#endif
}

The correct code should be:

extern void foo();
extern void bar();

void f(int i) {
  if (i > 0) {
#ifdef FOO
    foo();
#else
    bar();
#endif
  }
}

or

extern void foo();
extern void bar();

void f(int i) {
  if (i > 0) {
#ifdef FOO
    foo();
  }
#else
    bar();
  }
#endif
}
Comment 1 Richard 2016-01-21 01:30:40 PST
Here's another, similar case:

void f(int i) {
#if FOO
  if (i > 0)
#else
  if (i < 0)
#endif
    foo();
}