summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2019-10-18 15:21:06 +0000
committerKrasimir Georgiev <krasimir@google.com>2019-10-18 15:21:06 +0000
commiteff2a2ab2b51070133c39336c91b3f8d1c31e0c4 (patch)
tree0c580695486851f8e1abc9935cd7c0696c9714c1 /clang/unittests/Format/FormatTest.cpp
parent7e5d5ee873e14b7e3db0ee07fa402aca13f83a36 (diff)
downloadbcm5719-llvm-eff2a2ab2b51070133c39336c91b3f8d1c31e0c4.tar.gz
bcm5719-llvm-eff2a2ab2b51070133c39336c91b3f8d1c31e0c4.zip
[clang-format] fix regression recognizing casts in Obj-C calls
Summary: r373922 added checks for a few tokens that, following an `)` make it unlikely that the `)` is the closing paren of a cast expression. The specific check for `tok::l_square` there introduced a regression for casts of Obj-C calls, like: ``` (cast)[func arg] ``` From the tests added in r373922, I believe the `tok::l_square` case is added to capture the case where a non-cast `)` is directly followed by an attribute specifier, like: ``` int f(int x) [[noreturn]]; ``` I've specialized the code to look for such attribute specifier instead of `tok::l_square` in general. Also, I added a regression test and moved the test cases added in r373922 to an already existing place documenting other instances of historically misidentified casts. Reviewers: MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69164 llvm-svn: 375247
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp52
1 files changed, 25 insertions, 27 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b0d7f08892e..19269b24186 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7541,6 +7541,8 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("my_int a = (ns::my_int)-2;");
verifyFormat("case (my_int)ONE:");
verifyFormat("auto x = (X)this;");
+ // Casts in Obj-C style calls used to not be recognized as such.
+ verifyFormat("int a = [(type*)[((type*)val) arg] arg];", getGoogleStyle());
// FIXME: single value wrapped with paren will be treated as cast.
verifyFormat("void f(int i = (kValue)*kMask) {}");
@@ -7581,6 +7583,29 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("int a = alignof(int *) + b;", getGoogleStyle());
verifyFormat("bool b = f(g<int>) && c;");
verifyFormat("typedef void (*f)(int i) func;");
+ 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");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (aaaaaaaaaaaaaaaaa *)\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
@@ -14696,33 +14721,6 @@ 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");
-}
-
TEST_F(FormatTest, STLWhileNotDefineChed) {
verifyFormat("#if defined(while)\n"
"#define while EMIT WARNING C4005\n"
OpenPOWER on IntegriCloud