From f7cedcb5688664e0ae340e69d396a274b17d6901 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 18 Mar 2014 14:35:20 +0000 Subject: [PATCH] clang-format: Detect function-like macros only when upper case is used. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D3110 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204156 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 2 +- unittests/Format/FormatTest.cpp | 45 ++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 905c10bda1..d863b5db0c 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -726,7 +726,7 @@ void UnwrappedLineParser::parseStructuralElement() { if (FormatTok->Tok.is(tok::l_paren)) { parseParens(); if (FormatTok->NewlinesBefore > 0 && - tokenCanStartNewLine(FormatTok->Tok)) { + tokenCanStartNewLine(FormatTok->Tok) && Text == Text.upper()) { addUnwrappedLine(); return; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b0324015cd..282a443247 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2287,30 +2287,30 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { " ifstream(x)\n >> x;\n" "}\n")); EXPECT_EQ("int q() {\n" - " f(x)\n" + " F(x)\n" " if (1) {\n" " }\n" - " f(x)\n" + " F(x)\n" " while (1) {\n" " }\n" - " f(x)\n" - " g(x);\n" - " f(x)\n" + " F(x)\n" + " G(x);\n" + " F(x)\n" " try {\n" - " q();\n" + " Q();\n" " }\n" " catch (...) {\n" " }\n" "}\n", format("int q() {\n" - "f(x)\n" + "F(x)\n" "if (1) {}\n" - "f(x)\n" + "F(x)\n" "while (1) {}\n" - "f(x)\n" - "g(x);\n" - "f(x)\n" - "try { q(); } catch (...) {}\n" + "F(x)\n" + "G(x);\n" + "F(x)\n" + "try { Q(); } catch (...) {}\n" "}\n")); EXPECT_EQ("class A {\n" " A() : t(0) {}\n" @@ -2325,6 +2325,27 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { " A(X x)\n" " try : t(0) {} catch (...) {}\n" "};")); + EXPECT_EQ( + "class SomeClass {\n" + "public:\n" + " SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n" + "};", + format("class SomeClass {\n" + "public:\n" + " SomeClass()\n" + " EXCLUSIVE_LOCK_FUNCTION(mu_);\n" + "};")); + EXPECT_EQ( + "class SomeClass {\n" + "public:\n" + " SomeClass()\n" + " EXCLUSIVE_LOCK_FUNCTION(mu_);\n" + "};", + format("class SomeClass {\n" + "public:\n" + " SomeClass()\n" + " EXCLUSIVE_LOCK_FUNCTION(mu_);\n" + "};", getLLVMStyleWithColumns(40))); } TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) { -- 2.40.0