From 983e29fb810ac65bdfadd316ac5c67215f3e182b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 5 Apr 2016 11:46:06 +0000 Subject: [PATCH] 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 --- lib/Format/TokenAnnotator.cpp | 6 +++--- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) 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) {}"); -- 2.40.0