ilya-biryukov created this revision. ilya-biryukov added a reviewer: sammccall. Herald added a project: clang.
See the added test for a repro. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D58111 Files: clang/lib/Sema/SemaDeclCXX.cpp clang/test/Sema/crash-deduction-guide-access.cpp Index: clang/test/Sema/crash-deduction-guide-access.cpp =================================================================== --- /dev/null +++ clang/test/Sema/crash-deduction-guide-access.cpp @@ -0,0 +1,11 @@ +// RUN: not %clang_cc1 -x c++ -std=c++17 -fsyntax-only %s +template <typename U> +class Imp { + template <typename F> + explicit Imp(F f); +}; + +template <typename T> +class Cls { + explicit Imp() : f() {} +}; Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -3175,7 +3175,11 @@ // declared] with the same access [as the template]. if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(NonTemplateMember)) { auto *TD = DG->getDeducedTemplate(); - if (AS != TD->getAccess()) { + bool InSameScope = TD->getDeclContext()->getRedeclContext()->Equals( + DG->getDeclContext()->getRedeclContext()); + // Access specifiers are only meaningful if both the template and the + // deduction guide are from the same scope. + if (InSameScope && AS != TD->getAccess()) { Diag(DG->getBeginLoc(), diag::err_deduction_guide_wrong_access); Diag(TD->getBeginLoc(), diag::note_deduction_guide_template_access) << TD->getAccess();
Index: clang/test/Sema/crash-deduction-guide-access.cpp =================================================================== --- /dev/null +++ clang/test/Sema/crash-deduction-guide-access.cpp @@ -0,0 +1,11 @@ +// RUN: not %clang_cc1 -x c++ -std=c++17 -fsyntax-only %s +template <typename U> +class Imp { + template <typename F> + explicit Imp(F f); +}; + +template <typename T> +class Cls { + explicit Imp() : f() {} +}; Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -3175,7 +3175,11 @@ // declared] with the same access [as the template]. if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(NonTemplateMember)) { auto *TD = DG->getDeducedTemplate(); - if (AS != TD->getAccess()) { + bool InSameScope = TD->getDeclContext()->getRedeclContext()->Equals( + DG->getDeclContext()->getRedeclContext()); + // Access specifiers are only meaningful if both the template and the + // deduction guide are from the same scope. + if (InSameScope && AS != TD->getAccess()) { Diag(DG->getBeginLoc(), diag::err_deduction_guide_wrong_access); Diag(TD->getBeginLoc(), diag::note_deduction_guide_template_access) << TD->getAccess();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits