r237684 - clang-format: Correctly detect casts to qualified types.
Daniel Jasper
djasper at google.com
Tue May 19 04:18:40 PDT 2015
Author: djasper
Date: Tue May 19 06:18:39 2015
New Revision: 237684
URL: http://llvm.org/viewvc/llvm-project?rev=237684&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=237684&r1=237683&r2=237684&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue May 19 06:18:39 2015
@@ -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;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237684&r1=237683&r2=237684&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue May 19 06:18:39 2015
@@ -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) {}");
More information about the cfe-commits
mailing list