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 26228 - google-readability-braces-around-statements creates invalid code
Summary: google-readability-braces-around-statements creates invalid code
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Paweł Żukowski
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-20 21:26 PST by Richard
Modified: 2017-08-14 06:53 PDT (History)
4 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-20 21:26:21 PST
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");
}
}
Comment 1 Alexander Kornienko 2017-05-08 09:34:45 PDT
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("\
")
};
}
Comment 2 Alexander Kornienko 2017-05-09 05:40:23 PDT
Paweł's patch addressing this is in review here: https://reviews.llvm.org/D30748.