forked from OSchip/llvm-project
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:
parent
23a485a4ed
commit
29d39d54e7
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue