[clang-format] Use number of unwrapped lines for short namespace
Summary:
This patch makes the namespace comment fixer use the number of unwrapped lines
that a namespace spans to detect it that namespace is short, thus not needing
end comments to be added.
This is needed to ensure clang-format is idempotent. Previously, a short namespace
was detected by the original source code lines. This has the effect of requiring two
runs for this example:
```
namespace { class A; }
```
after first run:
```
namespace {
class A;
}
```
after second run:
```
namespace {
class A;
} // namespace
```
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D30528
llvm-svn: 296736
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 30cc749..7ab0c75 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -185,7 +185,7 @@
EXPECT_EQ("namespace N {\n"
"\n"
"int i;\n"
- "} // namespace N",
+ "}",
format("namespace N {\n"
"\n"
"int i;\n"
@@ -281,8 +281,7 @@
"}", LLVMWithNoNamespaceFix));
EXPECT_EQ("namespace {\n"
"int i;\n"
- "\n"
- "} // namespace",
+ "}",
format("namespace {\n"
"int i;\n"
"\n"
@@ -5460,7 +5459,7 @@
EXPECT_EQ("namespace N {\n"
"void f() {}\n"
"void g()\n"
- "}",
+ "} // namespace N",
format("namespace N { void f( ) { } void g( ) }"));
}
@@ -6140,8 +6139,8 @@
" void f() {}\n"
" int *a;\n"
"};\n"
- "}\n"
- "}");
+ "} // namespace b\n"
+ "} // namespace a");
}
TEST_F(FormatTest, SpecialTokensAtEndOfLine) {
@@ -7934,7 +7933,7 @@
"struct B {\n"
" int x;\n"
"};\n"
- "}\n",
+ "} // namespace a\n",
StroustrupBraceStyle);
verifyFormat("void foo()\n"