diff options
author | Daniel Jasper <djasper@google.com> | 2017-11-10 17:11:18 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2017-11-10 17:11:18 +0000 |
commit | 98efdc1da46347d20d688cf3b60d251035074e89 (patch) | |
tree | e4d4b9bfdab71733539397b1567fb415532c45c0 /lib/Format/UsingDeclarationsSorter.cpp | |
parent | 279bf36e21a10f5b9467835f588a80fe3f63640f (diff) |
[clang-format] Handle leading comments in using declaration
This fixes clang-format internal assertion for the following code:
/* override */ using std::string;
Patch by Igor Sugak. Thank you.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317901 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UsingDeclarationsSorter.cpp')
-rw-r--r-- | lib/Format/UsingDeclarationsSorter.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Format/UsingDeclarationsSorter.cpp b/lib/Format/UsingDeclarationsSorter.cpp index 72151137ee..2c124ec78b 100644 --- a/lib/Format/UsingDeclarationsSorter.cpp +++ b/lib/Format/UsingDeclarationsSorter.cpp @@ -172,15 +172,17 @@ std::pair<tooling::Replacements, unsigned> UsingDeclarationsSorter::analyze( tooling::Replacements Fixes; SmallVector<UsingDeclaration, 4> UsingDeclarations; for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) { + const auto *FirstTok = AnnotatedLines[I]->First; if (AnnotatedLines[I]->InPPDirective || - !AnnotatedLines[I]->startsWith(tok::kw_using) || - AnnotatedLines[I]->First->Finalized) { + !AnnotatedLines[I]->startsWith(tok::kw_using) || FirstTok->Finalized) { endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); continue; } - if (AnnotatedLines[I]->First->NewlinesBefore > 1) + if (FirstTok->NewlinesBefore > 1) endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); - std::string Label = computeUsingDeclarationLabel(AnnotatedLines[I]->First); + const auto *UsingTok = + FirstTok->is(tok::comment) ? FirstTok->getNextNonComment() : FirstTok; + std::string Label = computeUsingDeclarationLabel(UsingTok); if (Label.empty()) { endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes); continue; |