r207405 - clang-format: Improve binary operator detection.
Daniel Jasper
djasper at google.com
Mon Apr 28 02:19:29 PDT 2014
Author: djasper
Date: Mon Apr 28 04:19:28 2014
New Revision: 207405
URL: http://llvm.org/viewvc/llvm-project?rev=207405&view=rev
Log:
clang-format: Improve binary operator detection.
Before:
*(int *)(p &~3UL) = 0;
After:
*(int *)(p & ~3UL) = 0;
This fixes llvm.org/PR19464.
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=207405&r1=207404&r2=207405&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Apr 28 04:19:28 2014
@@ -682,7 +682,7 @@ private:
for (FormatToken *Previous = Current.Previous;
Previous && !Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
- if (Previous->is(tok::r_square))
+ if (Previous->isOneOf(tok::r_square, tok::r_paren))
Previous = Previous->MatchingParen;
if (Previous->Type == TT_BinaryOperator &&
Previous->isOneOf(tok::star, tok::amp)) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=207405&r1=207404&r2=207405&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 28 04:19:28 2014
@@ -4523,6 +4523,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
verifyIndependentOfContext("a * [self dostuff];");
verifyIndependentOfContext("int x = a * (a + b);");
verifyIndependentOfContext("(a *)(a + b);");
+ verifyIndependentOfContext("*(int *)(p & ~3UL) = 0;");
verifyIndependentOfContext("int *pa = (int *)&a;");
verifyIndependentOfContext("return sizeof(int **);");
verifyIndependentOfContext("return sizeof(int ******);");
More information about the cfe-commits
mailing list