r189450 - clang-format: Fix corner case in overloaded operator definitions.
Daniel Jasper
djasper at google.com
Wed Aug 28 00:27:35 PDT 2013
Author: djasper
Date: Wed Aug 28 02:27:35 2013
New Revision: 189450
URL: http://llvm.org/viewvc/llvm-project?rev=189450&view=rev
Log:
clang-format: Fix corner case in overloaded operator definitions.
Before:
SomeLoooooooooooooooooooooooooogType operator>
>(const SomeLooooooooooooooooooooooooogType &other);
SomeLoooooooooooooooooooooooooogType // break
operator>>(const SomeLooooooooooooooooooooooooogType &other);
After:
SomeLoooooooooooooooooooooooooogType
operator>>(const SomeLooooooooooooooooooooooooogType &other);
SomeLoooooooooooooooooooooooooogType // break
operator>>(const SomeLooooooooooooooooooooooooogType &other);
This fixes llvm.org/PR16328.
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=189450&r1=189449&r2=189450&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Aug 28 02:27:35 2013
@@ -393,6 +393,8 @@ private:
if (CurrentToken->isOneOf(tok::star, tok::amp))
CurrentToken->Type = TT_PointerOrReference;
consumeToken();
+ if (CurrentToken->Previous->Type == TT_BinaryOperator)
+ CurrentToken->Previous->Type = TT_OverloadedOperator;
}
if (CurrentToken) {
CurrentToken->Type = TT_OverloadedOperatorLParen;
@@ -1319,7 +1321,8 @@ bool TokenAnnotator::canBreakBefore(cons
Right.is(tok::question))
return true;
if (Right.Type == TT_RangeBasedForLoopColon ||
- Right.Type == TT_OverloadedOperatorLParen)
+ Right.Type == TT_OverloadedOperatorLParen ||
+ Right.Type == TT_OverloadedOperator)
return false;
if (Left.Type == TT_RangeBasedForLoopColon)
return true;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=189450&r1=189449&r2=189450&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug 28 02:27:35 2013
@@ -2610,6 +2610,8 @@ TEST_F(FormatTest, BreaksFunctionDeclara
// Treat overloaded operators like other functions.
verifyFormat("SomeLoooooooooooooooooooooooooogType\n"
"operator>(const SomeLoooooooooooooooooooooooooogType &other);");
+ verifyFormat("SomeLoooooooooooooooooooooooooogType\n"
+ "operator>>(const SomeLooooooooooooooooooooooooogType &other);");
verifyGoogleFormat(
"SomeLoooooooooooooooooooooooooooooogType operator<<(\n"
" const SomeLooooooooogType &a, const SomeLooooooooogType &b);");
More information about the cfe-commits
mailing list