]> granicus.if.org Git - clang/commitdiff
Don't put spaces around ##.
authorDaniel Jasper <djasper@google.com>
Tue, 8 Jan 2013 16:17:54 +0000 (16:17 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 8 Jan 2013 16:17:54 +0000 (16:17 +0000)
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

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 1aa7acf3de9811cb582ebb38f78e3059a1cacb28..120b54d83116ca5385d2ba4713ddd8e618a79c79 100644 (file)
@@ -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) ||
index c3f364db39668ad23de524e4a3a82ae5ca425d6a..677b0e99bda0e64b383123bce3c53afa8c4fefe8 100644 (file)
@@ -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) {