Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readability-braces-around-statements doesn't work well with macros #23159

Closed
llvmbot opened this issue Mar 4, 2015 · 2 comments
Closed

readability-braces-around-statements doesn't work well with macros #23159

llvmbot opened this issue Mar 4, 2015 · 2 comments
Labels
bugzilla clang-tidy worksforme

Comments

@llvmbot
Copy link
Collaborator

@llvmbot llvmbot commented Mar 4, 2015

Bugzilla Link 22785
Resolution WORKSFORME
Resolved on Oct 08, 2021 01:34
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @acopy,@mkurdej

Extended Description

$ cat test.cc
#define MACRO_1 i++
#define MACRO_2

void test(int i)
{
if( i % 3) i--; // OK
else if( i % 2) MACRO_1; // KO, no braces
else MACRO_2; // OK
}
$ clang_tidy -checks=-*,readability-braces-around-statements -fix test.cc --
2 warnings generated.
test.cc:6:19: warning: statement should be inside braces [readability-braces-around-statements]
if( i % 3) i--; // OK
^
test.cc:6:19: note: FIX-IT applied suggested code changes
if( i % 3) i--; // OK
^
test.cc:7:9: note: FIX-IT applied suggested code changes
else if( i % 2) MACRO_1; // KO, no braces
^
test.cc:8:13: warning: statement should be inside braces [readability-braces-around-statements]
else MACRO_2; // OK
^
test.cc:8:13: note: FIX-IT applied suggested code changes
else MACRO_2; // OK
^
test.cc:8:28: note: FIX-IT applied suggested code changes
else MACRO_2; // OK
^
clang-tidy applied 4 of 4 suggested fixes.

@llvmbot
Copy link
Collaborator Author

@llvmbot llvmbot commented May 15, 2015

Another test case:

$ cat test.cc
#define M(x) x
int f(bool b) {
if (b)
return 1;
else
return 2;
if (b)
return 1;
else
M(return 2);
}
$ clang_tidy -fix test.cc --
3 warnings generated.
...
clang-tidy applied 6 of 6 suggested fixes.
$ cat test.cc
#define M(x) x
int f(bool b) {
if (b) {
return 1;
} else {
return 2;
}
if (b) {
return 1;
} else
M(return 2);
}

@acopy
Copy link
Mannequin

@acopy acopy mannequin commented Oct 8, 2021

Hello,

This two examples works fine with LLVM 11.0.0.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Quuxplusone Quuxplusone added the worksforme label Jan 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla clang-tidy worksforme
Projects
None yet
Development

No branches or pull requests

2 participants