[all-commits] [llvm/llvm-project] 50bdd6: [clang-format] [PR46130] When editing a file with ...

MyDeveloperDay via All-commits all-commits at lists.llvm.org
Sat May 30 05:16:09 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 50bdd60731130dbde81fa477ba8916c58039d73a
      https://github.com/llvm/llvm-project/commit/50bdd60731130dbde81fa477ba8916c58039d73a
  Author: mydeveloperday <mydeveloperday at gmail.com>
  Date:   2020-05-30 (Sat, 30 May 2020)

  Changed paths:
    M clang/lib/Format/NamespaceEndCommentsFixer.cpp
    M clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp

  Log Message:
  -----------
  [clang-format] [PR46130] When editing a file with unbalance {} the namespace comment fixer can incorrectly comment the wrong closing brace

Summary:
https://bugs.llvm.org/show_bug.cgi?id=46130   from Twitter https://twitter.com/ikautak/status/1265998988232159232

I have seen this myself many times.. if you have format on save and you work in an editor where you are constantly saving (:w muscle memory)

If you are in the middle of editing and somehow you've missed a { or } in your code, somewhere, often way below where you are at the bottom of your file the namespace comment fixer will have put the namespace on the previous closing brace.

This leads to you having to fix up the bottom of the file.

This revision prevents that happening by performing an initial pass of the tokens and simply counting the number of `{` and `}`  and ensuring they balance.

If they don't balance we don't do any namespace fixing as it will likely be unstable and incorrect.

Reviewed By: curdeius

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80830




More information about the All-commits mailing list