From: Ilya Biryukov Date: Tue, 12 Feb 2019 14:21:44 +0000 (+0000) Subject: [Sema] Fix a crash in access checking for deduction guides X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c1492e1e3debf7023b2c13d3dd5836caf340efe;p=clang [Sema] Fix a crash in access checking for deduction guides Summary: See the added test for a repro. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58111 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353840 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index c54e700f51..8badbbd3ea 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3175,7 +3175,11 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, // 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(); diff --git a/test/Sema/crash-deduction-guide-access.cpp b/test/Sema/crash-deduction-guide-access.cpp new file mode 100644 index 0000000000..c0203ef8c5 --- /dev/null +++ b/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() {} +};