From: Daniel Jasper Date: Tue, 8 Jan 2013 16:17:54 +0000 (+0000) Subject: Don't put spaces around ##. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=765561ff8fa636cc88d133b85ecb592094104554;p=clang Don't put spaces around ##. In Clang/LLVM this seems to be the more common formatting for ##s. There might still be case that we miss, but we'll fix those as we go along. Before: #define A(X) void function ## X(); After: #define A(X) void function##X(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171862 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 1aa7acf3de..120b54d831 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -928,6 +928,10 @@ private: bool spaceRequiredBetween(const AnnotatedToken &Left, const AnnotatedToken &Right) { + if (Right.is(tok::hashhash)) + return Left.is(tok::hash); + if (Left.is(tok::hashhash) || Left.is(tok::hash)) + return Right.is(tok::hash); if (Right.is(tok::r_paren) || Right.is(tok::semi) || Right.is(tok::comma)) return false; if (Left.is(tok::kw_template) && Right.is(tok::less)) @@ -962,8 +966,6 @@ private: return true; if (Left.is(tok::l_paren)) return false; - if (Left.is(tok::hash)) - return false; if (Right.is(tok::l_paren)) { return Left.is(tok::kw_if) || Left.is(tok::kw_for) || Left.is(tok::kw_while) || Left.is(tok::kw_switch) || diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c3f364db39..677b0e99bd 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -551,6 +551,15 @@ TEST_F(FormatTest, HashInMacroDefinition) { " { \\\n" " f(#c);\\\n" " }", getLLVMStyleWithColumns(11)); + + verifyFormat("#define A(X) \\\n" + " void function##X()", getLLVMStyleWithColumns(22)); + + verifyFormat("#define A(a, b, c) \\\n" + " void a##b##c()", getLLVMStyleWithColumns(22)); + + verifyFormat("#define A \\\n" + " void # ## #", getLLVMStyleWithColumns(22)); } TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {