[clangd] Fix readability-else-after-return 'Adding a note without main diagnostic' crash

Fix a crash in clangd caused by an (admittidly incorrect) Remark diagnositic being emitted from readability-else-after-return.
This crash doesn't occur in clang-tidy so there are no tests there for this.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D81785
This commit is contained in:
njames93
2020-06-16 12:01:56 +01:00
committed by Nathan James
parent 503a26d8e4
commit 740575dc23
@@ -188,9 +188,8 @@ void ElseAfterReturnCheck::check(const MatchFinder::MatchResult &Result) {
if (IsLastInScope) {
// If the if statement is the last statement its enclosing statements
// scope, we can pull the decl out of the if statement.
DiagnosticBuilder Diag =
diag(ElseLoc, WarningMessage, clang::DiagnosticIDs::Level::Remark)
<< ControlFlowInterruptor;
DiagnosticBuilder Diag = diag(ElseLoc, WarningMessage)
<< ControlFlowInterruptor;
if (checkInitDeclUsageInElse(If) != nullptr) {
Diag << tooling::fixit::createReplacement(
SourceRange(If->getIfLoc()),