From 8835a32078c85f15f77bcd2c2221d4745e5b905c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 20 Oct 2014 13:56:30 +0000 Subject: [PATCH] clang-format: Fix overloaded operator edge case. Before: template void Call(F f) { f.template operator() (); } After: template void Call(F f) { f.template operator()(); } llvm-svn: 220202 --- clang/lib/Format/TokenAnnotator.cpp | 4 ++++ clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 33627e5..76de388 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1698,6 +1698,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, 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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a16ee2c..79e5ab11 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4844,6 +4844,7 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) { " return left.group < right.group;\n" "}"); verifyFormat("SomeType &operator=(const SomeType &S);"); + verifyFormat("f.template operator()();"); verifyGoogleFormat("operator void*();"); verifyGoogleFormat("operator SomeType>();"); -- 2.7.4