r373922 - [clang-format] [PR27004] omits leading space for noexcept when formatting operator delete()
Paul Hoad via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 10:03:44 PDT 2019
Author: paulhoad
Date: Mon Oct 7 10:03:44 2019
New Revision: 373922
URL: http://llvm.org/viewvc/llvm-project?rev=373922&view=rev
Log:
[clang-format] [PR27004] omits leading space for noexcept when formatting operator delete()
Summary:
clang-format is incorrectly thinking the parameter parens are part of a cast operation, this is resulting in there sometimes being not space between the paren and the noexcept (and other keywords like volatile etc..)
```
void operator++(int) noexcept;
void operator++(int &) noexcept;
void operator delete(void *, std::size_t, const std::nothrow_t &)noexcept;
```
Reviewers: klimek, owenpan, mitchell-stellar
Reviewed By: mitchell-stellar
Subscribers: cfe-commits
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D68481
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373922&r1=373921&r2=373922&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Oct 7 10:03:44 2019
@@ -1611,6 +1611,13 @@ private:
if (Tok.Next->is(tok::question))
return false;
+ // Functions which end with decorations like volatile, noexcept are unlikely
+ // to be casts.
+ if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
+ tok::kw_throw, tok::l_square, tok::arrow,
+ Keywords.kw_override, Keywords.kw_final))
+ return false;
+
// As Java has no function types, a "(" after the ")" likely means that this
// is a cast.
if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373922&r1=373921&r2=373922&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Oct 7 10:03:44 2019
@@ -14678,6 +14678,33 @@ TEST_F(FormatTest, AlternativeOperators)
*/
}
+TEST_F(FormatTest, NotCastRPaen) {
+
+ verifyFormat("void operator++(int) noexcept;");
+ verifyFormat("void operator++(int &) noexcept;");
+ verifyFormat("void operator delete(void *, std::size_t, const std::nothrow_t "
+ "&) noexcept;");
+ verifyFormat(
+ "void operator delete(std::size_t, const std::nothrow_t &) noexcept;");
+ verifyFormat("void operator delete(const std::nothrow_t &) noexcept;");
+ verifyFormat("void operator delete(std::nothrow_t &) noexcept;");
+ verifyFormat("void operator delete(nothrow_t &) noexcept;");
+ verifyFormat("void operator delete(foo &) noexcept;");
+ verifyFormat("void operator delete(foo) noexcept;");
+ verifyFormat("void operator delete(int) noexcept;");
+ verifyFormat("void operator delete(int &) noexcept;");
+ verifyFormat("void operator delete(int &) volatile noexcept;");
+ verifyFormat("void operator delete(int &) const");
+ verifyFormat("void operator delete(int &) = default");
+ verifyFormat("void operator delete(int &) = delete");
+ verifyFormat("void operator delete(int &) [[noreturn]]");
+ verifyFormat("void operator delete(int &) throw();");
+ verifyFormat("void operator delete(int &) throw(int);");
+ verifyFormat("auto operator delete(int &) -> int;");
+ verifyFormat("auto operator delete(int &) override");
+ verifyFormat("auto operator delete(int &) final");
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
More information about the cfe-commits
mailing list