summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-01-23 19:04:49 +0000
committerDaniel Jasper <djasper@google.com>2015-01-23 19:04:49 +0000
commit7509216a41e7fe14405c6859d88193311e66081d (patch)
treed520607a87c535afca34cea5e472b6e5a9b0665b /clang
parent0823ea636ed82153c726acf557796ed9cea42040 (diff)
downloadbcm5719-llvm-7509216a41e7fe14405c6859d88193311e66081d.tar.gz
bcm5719-llvm-7509216a41e7fe14405c6859d88193311e66081d.zip
clang-format: Fix incorrect classification of "*".
Before: *a = b *c; After: *a = b * c; llvm-svn: 226923
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp27
-rw-r--r--clang/unittests/Format/FormatTest.cpp1
2 files changed, 15 insertions, 13 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 91aeb73e552..02f80ae98d6 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -747,22 +747,23 @@ private:
void modifyContext(const FormatToken &Current) {
if (Current.getPrecedence() == prec::Assignment &&
- !Line.First->isOneOf(tok::kw_template, tok::kw_using,
- TT_UnaryOperator) &&
+ !Line.First->isOneOf(tok::kw_template, tok::kw_using) &&
(!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
Contexts.back().IsExpression = true;
- for (FormatToken *Previous = Current.Previous;
- Previous && !Previous->isOneOf(tok::comma, tok::semi);
- Previous = Previous->Previous) {
- if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
- Previous = Previous->MatchingParen;
- if (!Previous)
- break;
+ if (!Line.First->is(TT_UnaryOperator)) {
+ for (FormatToken *Previous = Current.Previous;
+ Previous && !Previous->isOneOf(tok::comma, tok::semi);
+ Previous = Previous->Previous) {
+ if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
+ Previous = Previous->MatchingParen;
+ if (!Previous)
+ break;
+ }
+ if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
+ Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
+ Previous->Previous->isNot(tok::equal))
+ Previous->Type = TT_PointerOrReference;
}
- if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
- Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
- Previous->Previous->isNot(tok::equal))
- Previous->Type = TT_PointerOrReference;
}
} else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
Contexts.back().IsExpression = true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 7c86d14a528..faf7c436883 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5220,6 +5220,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
verifyGoogleFormat("**outparam = 1;");
+ verifyGoogleFormat("*outparam = a * b;");
verifyGoogleFormat("int main(int argc, char** argv) {}");
verifyGoogleFormat("A<int*> a;");
verifyGoogleFormat("A<int**> a;");
OpenPOWER on IntegriCloud