clang-format: Fix namespace end comments for namespaces with attributes and macros.
Fixes PR39247.
While here, also make C++20 `namespace A::inline B::inline C` nested
inline namespaced definitions work.
Before:
#define DEPRECATE_WOOF [[deprecated("meow")]]
namespace DEPRECATE_WOOF woof {
void f() {}
} // namespace DEPRECATE_WOOFwoof
namespace [[deprecated("meow")]] woof {
void f() {}
} // namespace [[deprecated("meow")]]woof
namespace woof::inline bark {
void f() {}
} // namespace woof::inlinebark
Now:
#define DEPRECATE_WOOF [[deprecated("meow")]]
namespace DEPRECATE_WOOF woof {
void f() {}
} // namespace woof
namespace [[deprecated("meow")]] woof {
void f() {}
} // namespace woof
namespace woof::inline bark {
void f() {}
} // namespace woof::inline bark
(In addition to the fixed namespace end comments, also note the correct
indent of the namespace contents.)
Differential Revision: https://reviews.llvm.org/D65125
llvm-svn: 366831
diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
index 44cb4ef6..ad77c74 100644
--- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -77,6 +77,44 @@
"int i;\n"
"int j;\n"
"}"));
+
+ EXPECT_EQ("namespace [[deprecated(\"foo\")]] A::B {\n"
+ "int i;\n"
+ "int j;\n"
+ "}// namespace A::B",
+ fixNamespaceEndComments("namespace [[deprecated(\"foo\")]] A::B {\n"
+ "int i;\n"
+ "int j;\n"
+ "}"));
+
+ EXPECT_EQ("namespace [[deprecated(\"foo\")]] A::inline B::inline C {\n"
+ "int i;\n"
+ "int j;\n"
+ "}// namespace A::inline B::inline C",
+ fixNamespaceEndComments(
+ "namespace [[deprecated(\"foo\")]] A::inline B::inline C {\n"
+ "int i;\n"
+ "int j;\n"
+ "}"));
+
+ EXPECT_EQ("namespace DEPRECATED A::B {\n"
+ "int i;\n"
+ "int j;\n"
+ "}// namespace A::B",
+ fixNamespaceEndComments("namespace DEPRECATED A::B {\n"
+ "int i;\n"
+ "int j;\n"
+ "}"));
+
+ EXPECT_EQ("inline namespace [[deprecated]] A {\n"
+ "int i;\n"
+ "int j;\n"
+ "}// namespace A",
+ fixNamespaceEndComments("inline namespace [[deprecated]] A {\n"
+ "int i;\n"
+ "int j;\n"
+ "}"));
+
EXPECT_EQ("namespace ::A {\n"
"int i;\n"
"int j;\n"
@@ -410,7 +448,8 @@
/*Ranges=*/{1, tooling::Range(16, 3)}));
}
-TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddCommentAfterRBraceInPPDirective) {
+TEST_F(NamespaceEndCommentsFixerTest,
+ DoesNotAddCommentAfterRBraceInPPDirective) {
EXPECT_EQ("#define SAD \\\n"
"namespace A { \\\n"
"int i; \\\n"