aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2019-02-12 14:21:44 +0000
committerIlya Biryukov <ibiryukov@google.com>2019-02-12 14:21:44 +0000
commit2c1492e1e3debf7023b2c13d3dd5836caf340efe (patch)
treebae6841cb5d7ee12f7b57f168745c8a4bedb3dd4
parentc4184ecbbc8e51a8c1a225321bc2b17b17791abc (diff)
downloadclang-2c1492e1e3debf7023b2c13d3dd5836caf340efe.tar.gz
[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
-rw-r--r--lib/Sema/SemaDeclCXX.cpp6
-rw-r--r--test/Sema/crash-deduction-guide-access.cpp11
2 files changed, 16 insertions, 1 deletions
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<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();
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 <typename U>
+class Imp {
+ template <typename F>
+ explicit Imp(F f);
+};
+
+template <typename T>
+class Cls {
+ explicit Imp() : f() {}
+};