diff options
| author | Daniel Jasper <djasper@google.com> | 2013-06-01 18:56:00 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-06-01 18:56:00 +0000 |
| commit | d589391d079d49c8c1c28fe648dae0bd2e20d154 (patch) | |
| tree | 90c876892ffa480ffe55eadaf37661601784be96 | |
| parent | 7c275640e734a47fc4121590dbf772cf996aabb3 (diff) | |
| download | bcm5719-llvm-d589391d079d49c8c1c28fe648dae0bd2e20d154.tar.gz bcm5719-llvm-d589391d079d49c8c1c28fe648dae0bd2e20d154.zip | |
Improve recognition of template parameters.
Before: return a<b &&c> d;
After: return a < b && c > d;
llvm-svn: 183077
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 9 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 5b228f8acea..61f43a02010 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -53,8 +53,15 @@ private: if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace, tok::question, tok::colon)) return false; + // If a && or || is found and interpreted as a binary operator, this set + // of angles is like part of something like "a < b && c > d". If the + // angles are inside an expression, the ||/&& might also be a binary + // operator that was misinterpreted because we are parsing template + // parameters. + // FIXME: This is getting out of hand, write a decent parser. if (CurrentToken->Previous->isOneOf(tok::pipepipe, tok::ampamp) && - CurrentToken->Previous->Type != TT_PointerOrReference && + (CurrentToken->Previous->Type == TT_BinaryOperator || + Contexts[Contexts.size() - 2].IsExpression) && Line.First->isNot(tok::kw_template)) return false; updateParameterCount(Left, CurrentToken); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 0b35abeb9b0..24e4769274f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2893,6 +2893,13 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { verifyFormat("f<int>();"); verifyFormat("template <typename T> void f() {}"); + + // Not template parameters. + verifyFormat("return a < b && c > d;"); + verifyFormat("void f() {\n" + " while (a < b && c > d) {\n" + " }\n" + "}"); } TEST_F(FormatTest, UnderstandsBinaryOperators) { |

