From: Daniel Jasper Date: Tue, 19 May 2015 11:18:39 +0000 (+0000) Subject: clang-format: Correctly detect casts to qualified types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=857905e4b431fd93282bbd44c6cff159d3ec8840;p=clang clang-format: Correctly detect casts to qualified types. 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index d3122615c8..772fa1d239 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3903ac31e8..9c3448ad83 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) {}");