]> granicus.if.org Git - clang/commitdiff
[Sema] Fix a crash in access checking for deduction guides
authorIlya Biryukov <ibiryukov@google.com>
Tue, 12 Feb 2019 14:21:44 +0000 (14:21 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Tue, 12 Feb 2019 14:21:44 +0000 (14:21 +0000)
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

lib/Sema/SemaDeclCXX.cpp
test/Sema/crash-deduction-guide-access.cpp [new file with mode: 0644]

index c54e700f51ca709386af05c5dcff94caf4da175e..8badbbd3ead1d8252edcc76a65b9a2b7e193965c 100644 (file)
@@ -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 (file)
index 0000000..c0203ef
--- /dev/null
@@ -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() {}
+};