diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-08 16:17:54 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-08 16:17:54 +0000 |
commit | 765561ff8fa636cc88d133b85ecb592094104554 (patch) | |
tree | 6aa314182e7cc20cbc5ba7967614beb6969068c1 | |
parent | a879a164495db6daa4d809fbaba1617c9ade5919 (diff) |
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
-rw-r--r-- | lib/Format/Format.cpp | 6 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 9 |
2 files changed, 13 insertions, 2 deletions
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) { |