From 058f6f889a1df37f31bcf6b82060b8f815113471 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 16 May 2013 10:17:39 +0000 Subject: [PATCH] Comments should not prevent single-line functions. Before: void f() {} void g() { } // comment After: void f() {} void g() {} // comment git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181996 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 4 ++-- unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 7db75b715b..93d2a93be9 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1418,7 +1418,7 @@ private: return; AnnotatedToken *Tok = &(I + 1)->First; - if (Tok->Children.empty() && Tok->is(tok::r_brace) && + if (Tok->getNextNoneComment() == NULL && Tok->is(tok::r_brace) && !Tok->MustBreakBefore) { // We merge empty blocks even if the line exceeds the column limit. Tok->SpacesRequiredBefore = 0; @@ -1443,7 +1443,7 @@ private: // Last, check that the third line contains a single closing brace. Tok = &(I + 2)->First; - if (!Tok->Children.empty() || Tok->isNot(tok::r_brace) || + if (Tok->getNextNoneComment() != NULL || Tok->isNot(tok::r_brace) || Tok->MustBreakBefore) return; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b39280edd8..8ee0245d1d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3043,6 +3043,8 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { " int a;\n" "#error {\n" "}"); + verifyFormat("void f() {} // comment"); + verifyFormat("void f() { int a; } // comment"); verifyFormat("void f() { return 42; }", getLLVMStyleWithColumns(23)); verifyFormat("void f() {\n return 42;\n}", getLLVMStyleWithColumns(22));