r353840 - [Sema] Fix a crash in access checking for deduction guides
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 12 06:21:44 PST 2019
Author: ibiryukov
Date: Tue Feb 12 06:21:44 2019
New Revision: 353840
URL: http://llvm.org/viewvc/llvm-project?rev=353840&view=rev
Log:
[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
Added:
cfe/trunk/test/Sema/crash-deduction-guide-access.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=353840&r1=353839&r2=353840&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Feb 12 06:21:44 2019
@@ -3175,7 +3175,11 @@ Sema::ActOnCXXMemberDeclarator(Scope *S,
// declared] with the same access [as the template].
if (auto *DG = dyn_cast<CXXDeductionGuideDecl>(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();
Added: cfe/trunk/test/Sema/crash-deduction-guide-access.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/crash-deduction-guide-access.cpp?rev=353840&view=auto
==============================================================================
--- cfe/trunk/test/Sema/crash-deduction-guide-access.cpp (added)
+++ cfe/trunk/test/Sema/crash-deduction-guide-access.cpp Tue Feb 12 06:21:44 2019
@@ -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() {}
+};
More information about the cfe-commits
mailing list