diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -10012,34 +10012,35 @@ } }; - auto DiagnoseODRMismatch = - [this](DiffResult &DR, NamedDecl *FirstRecord, StringRef FirstModule, - NamedDecl *SecondRecord, StringRef SecondModule) { - SourceLocation FirstLoc; - SourceRange FirstRange; - auto *FirstTag = dyn_cast(FirstRecord); - if (DR.FirstDiffType == EndOfClass && FirstTag) { - FirstLoc = FirstTag->getBraceRange().getEnd(); - } else { - FirstLoc = DR.FirstDecl->getLocation(); - FirstRange = DR.FirstDecl->getSourceRange(); - } - Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) - << FirstRecord << FirstModule.empty() << FirstModule << FirstRange - << DR.FirstDiffType; - - SourceLocation SecondLoc; - SourceRange SecondRange; - auto *SecondTag = dyn_cast(SecondRecord); - if (DR.SecondDiffType == EndOfClass && SecondTag) { - SecondLoc = SecondTag->getBraceRange().getEnd(); - } else { - SecondLoc = DR.SecondDecl->getLocation(); - SecondRange = DR.SecondDecl->getSourceRange(); - } - Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) - << SecondModule << SecondRange << DR.SecondDiffType; - }; + auto DiagnoseODRMismatch = [this](DiffResult &DR, NamedDecl *FirstRecord, + StringRef FirstModule, + NamedDecl *SecondRecord, + StringRef SecondModule) { + auto GetMismatchedDeclLoc = [](const NamedDecl *Container, + ODRMismatchDecl DiffType, const Decl *D) { + SourceLocation Loc; + SourceRange Range; + auto *Tag = dyn_cast(Container); + if (DiffType == EndOfClass && Tag) { + Loc = Tag->getBraceRange().getEnd(); + } else { + Loc = D->getLocation(); + Range = D->getSourceRange(); + } + return std::make_pair(Loc, Range); + }; + + auto FirstDiagInfo = + GetMismatchedDeclLoc(FirstRecord, DR.FirstDiffType, DR.FirstDecl); + Diag(FirstDiagInfo.first, diag::err_module_odr_violation_mismatch_decl) + << FirstRecord << FirstModule.empty() << FirstModule + << FirstDiagInfo.second << DR.FirstDiffType; + + auto SecondDiagInfo = + GetMismatchedDeclLoc(SecondRecord, DR.SecondDiffType, DR.SecondDecl); + Diag(SecondDiagInfo.first, diag::note_module_odr_violation_mismatch_decl) + << SecondModule << SecondDiagInfo.second << DR.SecondDiffType; + }; // Issue any pending ODR-failure diagnostics. for (auto &Merge : OdrMergeFailures) {