diff options
| author | Daniel Jasper <djasper@google.com> | 2013-07-16 11:37:21 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-07-16 11:37:21 +0000 |
| commit | 655d96ab3b5f705bf82a8326b101dabe6f698cb6 (patch) | |
| tree | c870a1dfb32a23f8fcc7a1e270aa05a9235f4860 /clang | |
| parent | 35bb463fb18d725ffb7dd852532c1d910687ea8a (diff) | |
| download | bcm5719-llvm-655d96ab3b5f705bf82a8326b101dabe6f698cb6.tar.gz bcm5719-llvm-655d96ab3b5f705bf82a8326b101dabe6f698cb6.zip | |
clang-format: Improve detection of function types.
This fixes an incorrect detection that led to a formatting error.
Before:
some_var = function (*some_pointer_var)[0];
After:
some_var = function(*some_pointer_var)[0];
llvm-svn: 186402
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 4 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 1d5904b3186..2d1c1e3f4ac 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -122,7 +122,9 @@ private: if (CurrentToken->is(tok::r_paren)) { if (MightBeFunctionType && CurrentToken->Next && - CurrentToken->Next->isOneOf(tok::l_paren, tok::l_square)) + (CurrentToken->Next->is(tok::l_paren) || + (CurrentToken->Next->is(tok::l_square) && + !Contexts.back().IsExpression))) Left->Type = TT_FunctionTypeLParen; Left->MatchingParen = CurrentToken; CurrentToken->MatchingParen = Left; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c8827c8dec6..747a140846b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3628,6 +3628,8 @@ TEST_F(FormatTest, FormatsFunctionTypes) { // Other constructs can look somewhat like function types: verifyFormat("A<sizeof(*x)> a;"); verifyFormat("#define DEREF_AND_CALL_F(x) f(*x)"); + verifyFormat("some_var = function(*some_pointer_var)[0];"); + verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }"); } TEST_F(FormatTest, BreaksLongDeclarations) { |

