From: Daniel Jasper Date: Tue, 5 Apr 2016 11:46:06 +0000 (+0000) Subject: clang-format: Fix cast detection on "this". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=983e29fb810ac65bdfadd316ac5c67215f3e182b;p=clang clang-format: Fix cast detection on "this". Before: auto x = (X) this; After: auto x = (X)this; This fixes llvm.org/PR27198. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265385 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b57faaad8b..ff0b5c19ba 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1172,9 +1172,9 @@ private: if (!LeftOfParens) return false; - // If the following token is an identifier, this is a cast. All cases where - // this can be something else are handled above. - if (Tok.Next->is(tok::identifier)) + // If the following token is an identifier or 'this', this is a cast. All + // cases where this can be something else are handled above. + if (Tok.Next->isOneOf(tok::identifier, tok::kw_this)) return true; if (!Tok.Next->Next) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 8f63cbe323..1107718348 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5984,6 +5984,7 @@ TEST_F(FormatTest, FormatsCasts) { verifyFormat("my_int a = (my_int)(my_int)-1;"); verifyFormat("my_int a = (ns::my_int)-2;"); verifyFormat("case (my_int)ONE:"); + verifyFormat("auto x = (X)this;"); // FIXME: single value wrapped with paren will be treated as cast. verifyFormat("void f(int i = (kValue)*kMask) {}");