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.

llvm-svn: 228522
This commit is contained in:
Daniel Jasper 2015-02-08 09:34:49 +00:00
parent 23a485a4ed
commit 29d39d54e7
2 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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) {