diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-05-22 10:07:56 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-05-22 10:07:56 +0000 |
commit | ea222a7951cfb3026a4b4ef592c942a4ef05b437 (patch) | |
tree | a415f38581a6f89cd2ef32720de047268f30f254 /clang/unittests/Format/FormatTestComments.cpp | |
parent | 6110be9759f6accf215c793c31278d6d4849bf6f (diff) | |
download | bcm5719-llvm-ea222a7951cfb3026a4b4ef592c942a4ef05b437.tar.gz bcm5719-llvm-ea222a7951cfb3026a4b4ef592c942a4ef05b437.zip |
[clang-format] Keep trailing preprocessor line comments separate from the following section comments
Summary:
r303415 changed the way a sequence of line comments following a preprocessor
macro is handled, which has the unfortunate effect of aligning a trailing
preprocessor line comment and following unrelated section comments, so:
```
#ifdef A // comment about A
// section comment
#endif
```
gets turned into:
```
#ifdef A // comment about A
// section comment
#endif
```
This patch fixes this by additionally checking the original start columns of
the line comments.
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D33394
llvm-svn: 303541
Diffstat (limited to 'clang/unittests/Format/FormatTestComments.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index f6d47104e11..959a61e271d 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -1020,6 +1020,38 @@ TEST_F(FormatTestComments, SplitsLongLinesInCommentsInPreprocessor) { getLLVMStyleWithColumns(20))); } +TEST_F(FormatTestComments, KeepsTrailingPPCommentsAndSectionCommentsSeparate) { + verifyFormat("#ifdef A // line about A\n" + "// section comment\n" + "#endif", + getLLVMStyleWithColumns(80)); + verifyFormat("#ifdef A // line 1 about A\n" + " // line 2 about A\n" + "// section comment\n" + "#endif", + getLLVMStyleWithColumns(80)); + EXPECT_EQ("#ifdef A // line 1 about A\n" + " // line 2 about A\n" + "// section comment\n" + "#endif", + format("#ifdef A // line 1 about A\n" + " // line 2 about A\n" + "// section comment\n" + "#endif", + getLLVMStyleWithColumns(80))); + verifyFormat("int f() {\n" + " int i;\n" + "#ifdef A // comment about A\n" + " // section comment 1\n" + " // section comment 2\n" + " i = 2;\n" + "#else // comment about #else\n" + " // section comment 3\n" + " i = 4;\n" + "#endif\n" + "}", getLLVMStyleWithColumns(80)); +} + TEST_F(FormatTestComments, CommentsInStaticInitializers) { EXPECT_EQ( "static SomeType type = {aaaaaaaaaaaaaaaaaaaa, /* comment */\n" |