Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2159,6 +2159,14 @@ while (Current) { if (isFunctionDeclarationName(*Current, Line)) Current->Type = TT_FunctionDeclarationName; + if (Current->is(TT_BlockComment)){ + std::cout << "TYPE"<Previous->isOneOf(TT_TemplateCloser,tok::l_paren) && Current->isTrailingComment()){ + Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments; + } + } + } if (Current->is(TT_LineComment)) { if (Current->Previous->BlockKind == BK_BracedInit && Current->Previous->opensScope()) Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -3659,6 +3659,8 @@ } TEST_F(FormatTest, FormatNestedBlocksInMacros) { + FormatStyle Style = getGoogleStyle(); + Style.SpacesBeforeTrailingComments = 0; EXPECT_EQ("#define MACRO() \\\n" " Debug(aaa, /* force line break */ \\\n" " { \\\n" @@ -3667,7 +3669,7 @@ " })", format("#define MACRO() Debug(aaa, /* force line break */ \\\n" " { int i; int j; })", - getGoogleStyle())); + Style)); EXPECT_EQ("#define A \\\n" " [] { \\\n" Index: unittests/Format/FormatTestComments.cpp =================================================================== --- unittests/Format/FormatTestComments.cpp +++ unittests/Format/FormatTestComments.cpp @@ -2600,6 +2600,33 @@ " // b"); } +TEST_F(FormatTestComments, SpacesBeforeTrailingBlockComments){ + FormatStyle Style = getGoogleStyle(); + Style.SpacesBeforeTrailingComments = 4; + EXPECT_EQ("int a; /*a*/\n" + "int b; /*a*/\n" + "int c; /*a*/\n" + "int d; /*a*/\n" + "int e; /*a*/\n" + "int f; /*a*/\n" + "int g; /*a*/\n" + "int h; /*a*/", + format("int a; /*a*/\n" + "int b; /*a*/\n" + "int c; /*a*/\n" + "int d; /*a*/\n" + "int e; /*a*/\n" + "int f; /*a*/\n" + "int g; /*a*/\n" + "int h; /*a*/", Style)); + EXPECT_EQ("#define A \\\n" + " int i; /*a*/ \\\n" + " int jjj; /*b*/", + format("#define A \\\n" + " int i; /*a*/ \\\n" + " int jjj; /*b*/", Style)); + +} TEST_F(FormatTestComments, AlignTrailingComments) { EXPECT_EQ("#define MACRO(V) \\\n" " V(Rt2) /* one more char */ \\\n"