r204709 - clang-format: Fix incorrect &/* detection.
Daniel Jasper
djasper at google.com
Tue Mar 25 03:52:46 PDT 2014
Author: djasper
Date: Tue Mar 25 05:52:45 2014
New Revision: 204709
URL: http://llvm.org/viewvc/llvm-project?rev=204709&view=rev
Log:
clang-format: Fix incorrect &/* detection.
Before:
STATIC_ASSERT((a &b) == 0);
After:
STATIC_ASSERT((a & b) == 0);
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=204709&r1=204708&r2=204709&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Mar 25 05:52:45 2014
@@ -98,8 +98,10 @@ private:
}
}
- if (Left->Previous && Left->Previous->isOneOf(tok::kw_static_assert,
- tok::kw_if, tok::kw_while)) {
+ if (Left->Previous &&
+ (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_if,
+ tok::kw_while, tok::l_paren, tok::comma) ||
+ Left->Previous->Type == TT_BinaryOperator)) {
// static_assert, if and while usually contain expressions.
Contexts.back().IsExpression = true;
} else if (Left->Previous && Left->Previous->is(tok::r_square) &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=204709&r1=204708&r2=204709&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Mar 25 05:52:45 2014
@@ -4527,6 +4527,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
FormatStyle PointerLeft = getLLVMStyle();
PointerLeft.PointerBindsToType = true;
verifyFormat("delete *x;", PointerLeft);
+ verifyFormat("STATIC_ASSERT((a & b) == 0);");
+ verifyFormat("STATIC_ASSERT(0 == (a & b));");
}
TEST_F(FormatTest, UnderstandsAttributes) {
More information about the cfe-commits
mailing list