[PATCH] D132189: [clang-format] Don't put `noexcept` on empty line following constructor
Emilia Dreamer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 20 03:37:11 PDT 2022
rymiel updated this revision to Diff 454191.
rymiel added a comment.
Extra tests, including token annotator tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132189/new/
https://reviews.llvm.org/D132189
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -770,6 +770,19 @@
EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
}
+TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {
+ auto Tokens = annotate("template <typename T>\n"
+ "DEPRECATED(\"Use NewClass::NewFunction instead.\")\n"
+ "string OldFunction(const string ¶meter) {}");
+ ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+ EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_FunctionAnnotationRParen);
+
+ Tokens = annotate("template <typename T>\n"
+ "A(T) noexcept;");
+ ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+ EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+}
+
TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
auto Annotate = [this](llvm::StringRef Code) {
return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9525,6 +9525,15 @@
verifyFormat("template <typename T> // T can be A, B or C.\n"
"struct C {};",
AlwaysBreak);
+ verifyFormat("template <typename T>\n"
+ "C(T) noexcept;",
+ AlwaysBreak);
+ verifyFormat("template <typename T>\n"
+ "ClassName(T) noexcept;",
+ AlwaysBreak);
+ verifyFormat("template <typename T>\n"
+ "POOR_NAME(T) noexcept;",
+ AlwaysBreak);
verifyFormat("template <enum E> class A {\n"
"public:\n"
" E *f();\n"
@@ -9535,6 +9544,9 @@
verifyFormat("template <typename T> class C {};", NeverBreak);
verifyFormat("template <typename T> void f();", NeverBreak);
verifyFormat("template <typename T> void f() {}", NeverBreak);
+ verifyFormat("template <typename T> C(T) noexcept;", NeverBreak);
+ verifyFormat("template <typename T> ClassName(T) noexcept;", NeverBreak);
+ verifyFormat("template <typename T> POOR_NAME(T) noexcept;", NeverBreak);
verifyFormat("template <typename T>\nvoid foo(aaaaaaaaaaaaaaaaaaaaaaaaaa "
"bbbbbbbbbbbbbbbbbbbb) {}",
NeverBreak);
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1922,7 +1922,7 @@
!Current.Next->isBinaryOperator() &&
!Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
tok::comma, tok::period, tok::arrow,
- tok::coloncolon)) {
+ tok::coloncolon, tok::kw_noexcept)) {
if (FormatToken *AfterParen = Current.MatchingParen->Next) {
// Make sure this isn't the return type of an Obj-C block declaration
if (AfterParen->isNot(tok::caret)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132189.454191.patch
Type: text/x-patch
Size: 3168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220820/b56a625c/attachment.bin>
More information about the cfe-commits
mailing list