summaryrefslogtreecommitdiffstats
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
commit6597fdd508f248f8bbb70b6fbf34b940677f2767 (patch)
treeaa262160c342289141eb927ee7436347945f9729
parentce667f6df9715d5708d846cc9054a781765fcfa7 (diff)
downloadbcm5719-llvm-6597fdd508f248f8bbb70b6fbf34b940677f2767.tar.gz
bcm5719-llvm-6597fdd508f248f8bbb70b6fbf34b940677f2767.zip
[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 llvm-svn: 353840
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp6
-rw-r--r--clang/test/Sema/crash-deduction-guide-access.cpp11
2 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c54e700f51c..8badbbd3ead 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/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/clang/test/Sema/crash-deduction-guide-access.cpp b/clang/test/Sema/crash-deduction-guide-access.cpp
new file mode 100644
index 00000000000..c0203ef8c51
--- /dev/null
+++ b/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() {}
+};
OpenPOWER on IntegriCloud