diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -643,8 +643,9 @@ while (!Jumps.empty()) { Stmt *Jump = Jumps.pop_back_val(); - // With a goto, - if (GotoStmt *GS = dyn_cast(Jump)) { + switch (Jump->getStmtClass()) { + case Stmt::GotoStmtClass: { + auto *GS = cast(Jump); // The label may not have a statement if it's coming from inline MS ASM. if (GS->getLabel()->getStmt()) { CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(), @@ -653,10 +654,10 @@ diag::warn_cxx98_compat_goto_into_protected_scope); } CheckGotoStmt(GS); - continue; + break; } - - if (auto *G = dyn_cast(Jump)) { + case Stmt::GCCAsmStmtClass: { + auto *G = cast(Jump); for (AddrLabelExpr *L : G->labels()) { LabelDecl *LD = L->getLabel(); unsigned JumpScope = LabelAndGotoScopes[G]; @@ -664,33 +665,38 @@ if (JumpScope != TargetScope) DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope); } - continue; + break; } - - // We only get indirect gotos here when they have a constant target. - if (IndirectGotoStmt *IGS = dyn_cast(Jump)) { + case Stmt::IndirectGotoStmtClass: { + // We only get indirect gotos here when they have a constant target. + auto *IGS = dyn_cast(Jump); LabelDecl *Target = IGS->getConstantTarget(); CheckJump(IGS, Target->getStmt(), IGS->getGotoLoc(), diag::err_goto_into_protected_scope, diag::ext_goto_into_protected_scope, diag::warn_cxx98_compat_goto_into_protected_scope); - continue; + break; } - - SwitchStmt *SS = cast(Jump); - for (SwitchCase *SC = SS->getSwitchCaseList(); SC; - SC = SC->getNextSwitchCase()) { - if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(SC))) - continue; - SourceLocation Loc; - if (CaseStmt *CS = dyn_cast(SC)) - Loc = CS->getBeginLoc(); - else if (DefaultStmt *DS = dyn_cast(SC)) - Loc = DS->getBeginLoc(); - else - Loc = SC->getBeginLoc(); - CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0, - diag::warn_cxx98_compat_switch_into_protected_scope); + case Stmt::SwitchStmtClass: { + auto *SS = cast(Jump); + for (SwitchCase *SC = SS->getSwitchCaseList(); SC; + SC = SC->getNextSwitchCase()) { + if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(SC))) + continue; + SourceLocation Loc; + if (const auto *CS = dyn_cast(SC)) + Loc = CS->getBeginLoc(); + else if (const auto *DS = dyn_cast(SC)) + Loc = DS->getBeginLoc(); + else + Loc = SC->getBeginLoc(); + CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0, + diag::warn_cxx98_compat_switch_into_protected_scope); + } + break; + } + default: + break; } } }