r220202 - clang-format: Fix overloaded operator edge case.
Daniel Jasper
djasper at google.com
Mon Oct 20 06:56:31 PDT 2014
Author: djasper
Date: Mon Oct 20 08:56:30 2014
New Revision: 220202
URL: http://llvm.org/viewvc/llvm-project?rev=220202&view=rev
Log:
clang-format: Fix overloaded operator edge case.
Before:
template <class F>
void Call(F f) {
f.template operator() <int>();
}
After:
template <class F>
void Call(F f) {
f.template operator()<int>();
}
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=220202&r1=220201&r2=220202&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Oct 20 08:56:30 2014
@@ -1698,6 +1698,10 @@ bool TokenAnnotator::spaceRequiredBefore
return true;
if (Tok.Previous->Type == TT_TemplateCloser && Tok.is(tok::l_paren))
return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;
+ if (Tok.Type == TT_TemplateOpener && Tok.Previous->is(tok::r_paren) &&
+ Tok.Previous->MatchingParen &&
+ Tok.Previous->MatchingParen->Type == TT_OverloadedOperatorLParen)
+ return false;
if (Tok.is(tok::less) && Tok.Previous->isNot(tok::l_paren) &&
Line.First->is(tok::hash))
return true;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=220202&r1=220201&r2=220202&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Oct 20 08:56:30 2014
@@ -4844,6 +4844,7 @@ TEST_F(FormatTest, UnderstandsOverloaded
" return left.group < right.group;\n"
"}");
verifyFormat("SomeType &operator=(const SomeType &S);");
+ verifyFormat("f.template operator()<int>();");
verifyGoogleFormat("operator void*();");
verifyGoogleFormat("operator SomeType<SomeType<int>>();");
More information about the cfe-commits
mailing list