[PATCH] [clang-tidy] Add check misc-braces-around-statements.

Alexander Kornienko alexfh at google.com
Wed Sep 24 07:37:57 PDT 2014


================
Comment at: clang-tidy/misc/BracesAroundStatementsCheck.cpp:81
@@ +80,3 @@
+    }
+  }
+}
----------------
Please add:

  else {
    llvm_unreachable("Invalid match"):
  }

or something similar.

================
Comment at: clang-tidy/misc/BracesAroundStatementsCheck.cpp:102
@@ +101,3 @@
+    // EndLoc points at ";"
+    EndLoc = EndLoc.getLocWithOffset(1);
+  }
----------------
Unfortunately, this is wrong. Consider these examples:

  if (x) f(); // here it will work
  if (x) f() /* here it won't */ ;
  do if(y) {}while (x); // and here too

I don't know if the AST provides a convenient way to find out if there's a semicolon behind the end of the statement and where it is located. I also don't know why the statements that end with a semicolon do not store its location or just include it in the source range. We need to ask someone more familiar with the AST.

================
Comment at: clang-tidy/misc/BracesAroundStatementsCheck.h:33
@@ +32,2 @@
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_BRACES_AROUND_STATEMENTS_CHECK_H
----------------
curdeius wrote:
> This line does not hold the 80-column limit, but clang-format leaves it as it is.
> What is the convention in this case?
It's fine here, as there's not much you can do. I was only talking about removing extra dashes from the file header comments.

http://reviews.llvm.org/D5395






More information about the cfe-commits mailing list