Index: lib/Sema/SemaDeclCXX.cpp =================================================================== --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -3175,7 +3175,7 @@ // declared] with the same access [as the template]. if (auto *DG = dyn_cast(NonTemplateMember)) { auto *TD = DG->getDeducedTemplate(); - if (AS != TD->getAccess()) { + if (AS != TD->getAccess() && TD->getAccess() != AS_none) { Diag(DG->getBeginLoc(), diag::err_deduction_guide_wrong_access); Diag(TD->getBeginLoc(), diag::note_deduction_guide_template_access) << TD->getAccess(); Index: test/SemaCXX/cxx1z-class-template-argument-deduction.cpp =================================================================== --- test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -353,6 +353,13 @@ template Protected(T) -> Protected; // expected-error {{different access}} template Private(T) -> Private; // expected-error {{different access}} }; + + // PR40552 + template struct Typo {}; // expected-note{{template is declared here}} + struct Type { + Typo(); // expected-error{{deduction guide must be declared in the same scope}} + // expected-error@-1{{deduction guide declaration without trailing return type}} + }; } namespace rdar41903969 {