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

google-readability-braces-around-statements creates invalid code #26602

Closed
LegalizeAdulthood opened this issue Jan 21, 2016 · 2 comments
Closed
Labels
bugzilla Issues migrated from bugzilla clang-tidy

Comments

@LegalizeAdulthood
Copy link
Contributor

Bugzilla Link 26228
Resolution FIXED
Resolved on Aug 14, 2017 06:53
Version unspecified
OS Linux

Extended Description

When a statement contains a line continuation, google-readability-braces-around-statements creates invalid code when fixit is applied.

Original code:

#include <stdio.h>

void f(int i) {
if (i > 0)
printf("This is one line\n
This is another line.\n
This is yet another line.\n");
}

Code as modified by clang-tidy:

#include <stdio.h>

void f(int i) {
if (i > 0) {
printf("This is one line\n
This is another line.\n
This is yet another line.\n")
};
}

Correct code should be:

#include <stdio.h>

void f(int i) {
if (i > 0) {
printf("This is one line\n
This is another line.\n
This is yet another line.\n");
}
}

@llvmbot
Copy link
Collaborator

llvmbot commented May 8, 2017

A smaller repro:
$ cat /tmp/q.cc
void f(const char p) {
if (!p)
f("
");
}
$ clang_tidy -checks=-
,google-readability-braces-around-statements -fix /tmp/q.cc --
1 warning generated.
/tmp/q.cc:2:10: warning: statement should be inside braces [google-readability-braces-around-statements]
if (!p)
^
/tmp/q.cc:2:10: note: FIX-IT applied suggested code changes
/tmp/q.cc:4:3: note: FIX-IT applied suggested code changes
");
^
clang-tidy applied 2 of 2 suggested fixes.
$ cat /tmp/q.cc
void f(const char *p) {
if (!p) {
f("
")
};
}

@llvmbot
Copy link
Collaborator

llvmbot commented May 9, 2017

Paweł's patch addressing this is in review here: https://reviews.llvm.org/D30748.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy
Projects
None yet
Development

No branches or pull requests

2 participants