Index: lib/Sema/SemaDeclCXX.cpp =================================================================== --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -3175,7 +3175,11 @@ // declared] with the same access [as the template]. if (auto *DG = dyn_cast(NonTemplateMember)) { auto *TD = DG->getDeducedTemplate(); - if (AS != TD->getAccess()) { + // Access specifiers are only meaningful if both the template and the + // deduction guide are from the same scope. + if (AS != TD->getAccess() && + TD->getDeclContext()->getRedeclContext()->Equals( + DG->getDeclContext()->getRedeclContext())) { Diag(DG->getBeginLoc(), diag::err_deduction_guide_wrong_access); Diag(TD->getBeginLoc(), diag::note_deduction_guide_template_access) << TD->getAccess(); Index: test/Sema/crash-deduction-guide-access.cpp =================================================================== --- test/Sema/crash-deduction-guide-access.cpp +++ test/Sema/crash-deduction-guide-access.cpp @@ -0,0 +1,11 @@ +// RUN: not %clang_cc1 -x c++ -std=c++17 -fsyntax-only %s +template +class Imp { + template + explicit Imp(F f); +}; + +template +class Cls { + explicit Imp() : f() {} +};