]> granicus.if.org Git - clang/commitdiff
clang-format: Fix cast detection on "this".
authorDaniel Jasper <djasper@google.com>
Tue, 5 Apr 2016 11:46:06 +0000 (11:46 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 5 Apr 2016 11:46:06 +0000 (11:46 +0000)
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
unittests/Format/FormatTest.cpp

index b57faaad8bbdb39d3e1e413dbfcb93c16527d637..ff0b5c19ba736808762d1bae5cfc40c9b26cae13 100644 (file)
@@ -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)
index 8f63cbe3232b9e1a44bdcbb50c15f2d30388f786..1107718348a4741dd700f352cbd90cd30bbbac15 100644 (file)
@@ -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) {}");