r228522 - clang-format: Correctly mark preprocessor lines in child blocks.
Daniel Jasper
djasper at google.com
Sun Feb 8 01:34:49 PST 2015
Author: djasper
Date: Sun Feb 8 03:34:49 2015
New Revision: 228522
URL: http://llvm.org/viewvc/llvm-project?rev=228522&view=rev
Log:
clang-format: Correctly mark preprocessor lines in child blocks.
This prevents contracting:
auto lambda = []() {
int a = 2
#if A
+ 2
#endif
;
};
into:
auto lambda = []() { int a = 2
#if A + 2
#endif ; };
Which is obviously BAD.
This fixes llvm.org/PR22496.
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=228522&r1=228521&r2=228522&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sun Feb 8 03:34:49 2015
@@ -1677,8 +1677,7 @@ void UnwrappedLineParser::readToken() {
(FormatTok->HasUnescapedNewline || FormatTok->IsFirst)) {
// If there is an unfinished unwrapped line, we flush the preprocessor
// directives only after that unwrapped line was finished later.
- bool SwitchToPreprocessorLines =
- !Line->Tokens.empty() && CurrentLines == &Lines;
+ bool SwitchToPreprocessorLines = !Line->Tokens.empty();
ScopedLineState BlockState(*this, SwitchToPreprocessorLines);
// Comments stored before the preprocessor directive need to be output
// before the preprocessor directive, at the same level as the
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=228522&r1=228521&r2=228522&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Feb 8 03:34:49 2015
@@ -9529,6 +9529,13 @@ TEST_F(FormatTest, FormatsLambdas) {
" doo_dah();\n"
" })) {\n"
"}");
+ verifyFormat("auto lambda = []() {\n"
+ " int a = 2\n"
+ "#if A\n"
+ " + 2\n"
+ "#endif\n"
+ " ;\n"
+ "};");
}
TEST_F(FormatTest, FormatsBlocks) {
More information about the cfe-commits
mailing list