-
- Downloads
clang-format: fix block OpeningLineIndex around preprocessor
Summary: The current code would return an incorrect value when a preprocessor directive is present immediately after the opening brace: this causes the nanespace end comment fixer to break in some places, for exemple it would not add the comment in this case: namespace a { #define FOO } Fixing the computation is simple enough, but it was breaking a feature, as it would cause comments to be added also when the namespace declaration was dependant on conditional compilation. To fix this, a hash of the current preprocessor stack/branches is computed at the beginning of parseBlock(), so that we explicitely do not store the OpeningLineIndex when the beginning and end of the block are not in the same preprocessor conditions. Tthe hash is computed based on the line, but this could propbably be improved by using the actual condition, so that clang-format would be able to match multiple identical #ifdef blocks. Reviewers: krasimir, djasper Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35483 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309369 91177308-0d34-0410-b5e6-96231b3b80d8
Showing
- lib/Format/UnwrappedLineParser.cpp 42 additions, 12 deletionslib/Format/UnwrappedLineParser.cpp
- lib/Format/UnwrappedLineParser.h 13 additions, 2 deletionslib/Format/UnwrappedLineParser.h
- unittests/Format/NamespaceEndCommentsFixerTest.cpp 128 additions, 0 deletionsunittests/Format/NamespaceEndCommentsFixerTest.cpp
Loading
Please register or sign in to comment