diff options
| author | Daniel Jasper <djasper@google.com> | 2013-09-02 09:20:39 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-09-02 09:20:39 +0000 |
| commit | 42401c8d132bd2c3cbdd2d4f5060e1f14767198b (patch) | |
| tree | ab37ec87122e16ae825412e594affe72576c928a /clang | |
| parent | bbd5f46696e00240ff8e08c6bfb7f2b6bb7dac77 (diff) | |
| download | bcm5719-llvm-42401c8d132bd2c3cbdd2d4f5060e1f14767198b.tar.gz bcm5719-llvm-42401c8d132bd2c3cbdd2d4f5060e1f14767198b.zip | |
clang-format: Fix segfault in overloaded operator parsing.
Before, constructs like:
using A::operator+;
caused a segfault. This fixes llvm.org/PR17050.
llvm-svn: 189749
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index d2cb5a8723b..5b9802ddd6e 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -389,11 +389,12 @@ private: Tok->Type = TT_BinaryOperator; break; case tok::kw_operator: - while (CurrentToken && CurrentToken->isNot(tok::l_paren)) { + while (CurrentToken && + !CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) { if (CurrentToken->isOneOf(tok::star, tok::amp)) CurrentToken->Type = TT_PointerOrReference; consumeToken(); - if (CurrentToken->Previous->Type == TT_BinaryOperator) + if (CurrentToken && CurrentToken->Previous->Type == TT_BinaryOperator) CurrentToken->Previous->Type = TT_OverloadedOperator; } if (CurrentToken) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 51577a66c7f..bdbc1555e42 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3625,6 +3625,8 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) { verifyGoogleFormat("operator void*();"); verifyGoogleFormat("operator SomeType<SomeType<int>>();"); + + verifyFormat("using A::operator+;"); } TEST_F(FormatTest, UnderstandsNewAndDelete) { |

