From 8cc4bbe4d823053c13d1e0c46fb25987d1ab18bc Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 5 Jul 2021 13:25:29 +0200 Subject: [PATCH] ClangFormat: Prepend a space character to our inserted line comment Otherwise, we could introduce unwanted syntactical constructs, for instance if the previous character is an asterisk. Fixes: QTCREATORBUG-25966 Change-Id: Ic0b535861bc1cb4f5f93d06bb11d0f3c7c583893 Reviewed-by: Eike Ziller --- src/plugins/clangformat/clangformatbaseindenter.cpp | 4 ++-- tests/unit/unittest/clangformat-test.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp index e210263770f..fa95514ca32 100644 --- a/src/plugins/clangformat/clangformatbaseindenter.cpp +++ b/src/plugins/clangformat/clangformatbaseindenter.cpp @@ -300,8 +300,8 @@ int forceIndentWithExtraText(QByteArray &buffer, if (block.previous().isValid()) { const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer, block.blockNumber()) + block.previous().text().length(); - buffer.insert(prevEndOffset, "//"); - extraLength += 2; + buffer.insert(prevEndOffset, " //"); + extraLength += 3; } } buffer.insert(utf8Offset + extraLength, dummyText); diff --git a/tests/unit/unittest/clangformat-test.cpp b/tests/unit/unittest/clangformat-test.cpp index b6312866927..9aec542edfd 100644 --- a/tests/unit/unittest/clangformat-test.cpp +++ b/tests/unit/unittest/clangformat-test.cpp @@ -957,7 +957,7 @@ TEST_F(ClangFormat, ChainedMemberFunctionCalls) " .func();")); } -TEST_F(ClangFormat, DISABLED_CommentBlock) +TEST_F(ClangFormat, CommentBlock) { insertLines({"/****************************************************************************", "**",