Index: lib/Sema/AnalysisBasedWarnings.cpp =================================================================== --- lib/Sema/AnalysisBasedWarnings.cpp +++ lib/Sema/AnalysisBasedWarnings.cpp @@ -972,7 +972,7 @@ } } - bool checkFallThroughIntoBlock(const CFGBlock &B, int &AnnotatedCnt) { + bool checkFallThroughIntoBlock(const CFGBlock &B, int &AnnotatedCnt, bool isTemplateInstantiation) { assert(!ReachableBlocks.empty() && "ReachableBlocks empty"); int UnannotatedCnt = 0; @@ -1002,8 +1002,12 @@ ElemIt != ElemEnd; ++ElemIt) { if (Optional CS = ElemIt->getAs()) { if (const AttributedStmt *AS = asFallThroughAttr(CS->getStmt())) { - S.Diag(AS->getLocStart(), - diag::warn_fallthrough_attr_unreachable); + // Don't issue a warning for an unreachable fallthrough + // attribute in template instantiations as it may not be + // unreachable in all instantiations of the template + if (!isTemplateInstantiation) + S.Diag(AS->getLocStart(), + diag::warn_fallthrough_attr_unreachable); markFallthroughVisited(AS); ++AnnotatedCnt; break; @@ -1164,7 +1168,10 @@ int AnnotatedCnt; - if (!FM.checkFallThroughIntoBlock(*B, AnnotatedCnt)) + bool isTemplateInstantiation = false; + if (const FunctionDecl *Function = dyn_cast(AC.getDecl())) + isTemplateInstantiation = Function->isTemplateInstantiation(); + if (!FM.checkFallThroughIntoBlock(*B, AnnotatedCnt, isTemplateInstantiation)) continue; S.Diag(Label->getLocStart(),