aboutsummaryrefslogtreecommitdiff
path: root/lib
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
commitfa738af8a2b2b47ce6be83f883c6ff814ece1f18 (patch)
tree4b2cefb0a2ac9b656c1d57cce53c36011c3855f5 /lib
parent92bf0539a1e2abe2e328e15d2c9e685d696fd378 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375247 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Format/TokenAnnotator.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 9823a5af9c..7aa1f378f0 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1607,8 +1607,9 @@ private:
// 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))
+ tok::kw_throw, tok::arrow, Keywords.kw_override,
+ Keywords.kw_final) ||
+ isCpp11AttributeSpecifier(*Tok.Next))
return false;
// As Java has no function types, a "(" after the ")" likely means that this