]> granicus.if.org Git - clang/commitdiff
clang-format: Correctly detect casts to qualified types.
authorDaniel Jasper <djasper@google.com>
Tue, 19 May 2015 11:18:39 +0000 (11:18 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 19 May 2015 11:18:39 +0000 (11:18 +0000)
Before:
  ns::E f() { return (ns::E) - 1; }

After:
  ns::E f() { return (ns::E)-1; }

This fixes llvm.org/PR23503.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237684 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index d3122615c83cd525a1d2450133f81fe92deaad12..772fa1d2390589892d7749c6a74081017781cbb0 100644 (file)
@@ -1082,7 +1082,8 @@ private:
         }
 
         for (; Prev != Tok.MatchingParen; Prev = Prev->Previous) {
-          if (!Prev || !Prev->isOneOf(tok::kw_const, tok::identifier)) {
+          if (!Prev ||
+              !Prev->isOneOf(tok::kw_const, tok::identifier, tok::coloncolon)) {
             IsCast = false;
             break;
           }
index 3903ac31e83a69bbf688bd643de76dc23bb7decd..9c3448ad83b11eed33634a696689334656d5dde7 100644 (file)
@@ -5765,6 +5765,7 @@ TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("my_int a = (const my_int)-1;");
   verifyFormat("my_int a = (const my_int *)-1;");
   verifyFormat("my_int a = (my_int)(my_int)-1;");
+  verifyFormat("my_int a = (ns::my_int)-2;");
 
   // FIXME: single value wrapped with paren will be treated as cast.
   verifyFormat("void f(int i = (kValue)*kMask) {}");