[PATCH] D74214: [clang-tidy] Fix PR#34798 'readability-braces-around-statements breaks statements containing braces.'

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 11 01:11:35 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp:30
       Lexer::getRawToken(Beginning, Tok, SM, Context->getLangOpts());
-  assert(!Invalid && "Expected a valid token.");
+  if (!Invalid) {
+    Kind = Tok.getKind();
----------------
Elide the braces.


================
Comment at: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp:40
+  tok::TokenKind Kind;
+  if (tryGetTokenKind(Loc, SM, Context, Kind)) {
+    return Kind;
----------------
Elide braces


================
Comment at: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp:76-77
+
+  // We need to check that it is not 'InitListExpr' which ends with 
+  // the tokens '};' because it will break the following analysis
+  tok::TokenKind NextTokKind;
----------------
Is there evidence that this behavior is desired? I have a hunch that this is a bug in Clang -- not all `InitListExpr`s will terminate with a semicolon, such as ones that appear as function arguments, like `foo({1, 2, 3});`, so I'm surprised to see it included here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74214/new/

https://reviews.llvm.org/D74214





More information about the cfe-commits mailing list