[clang] 7ad6c84 - [clang] Fix an assertion crash in delayed access check.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 05:03:14 PST 2020
Author: Haojian Wu
Date: 2020-11-13T14:02:57+01:00
New Revision: 7ad6c8414ce2c229129c93281835eb9457cf0bfb
URL: https://github.com/llvm/llvm-project/commit/7ad6c8414ce2c229129c93281835eb9457cf0bfb
DIFF: https://github.com/llvm/llvm-project/commit/7ad6c8414ce2c229129c93281835eb9457cf0bfb.diff
LOG: [clang] Fix an assertion crash in delayed access check.
`TD->getTemplatedDecl()` might not be a DeclContext variant, which can
trigger an assertion inside `isa<>`.
Differential Revision: https://reviews.llvm.org/D91380
Added:
clang/test/SemaCXX/cxx14-access.cpp
Modified:
clang/lib/Sema/SemaAccess.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index bd15b81cbed0..be30445d143c 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -1476,7 +1476,8 @@ void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *D) {
} else if (FunctionDecl *FN = dyn_cast<FunctionDecl>(D)) {
DC = FN;
} else if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) {
- DC = cast<DeclContext>(TD->getTemplatedDecl());
+ if (isa<DeclContext>(TD->getTemplatedDecl()))
+ DC = cast<DeclContext>(TD->getTemplatedDecl());
}
EffectiveContext EC(DC);
diff --git a/clang/test/SemaCXX/cxx14-access.cpp b/clang/test/SemaCXX/cxx14-access.cpp
new file mode 100644
index 000000000000..ea129b175696
--- /dev/null
+++ b/clang/test/SemaCXX/cxx14-access.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+
+namespace NoCrashOnDelayedAccessCheck {
+class Foo {
+ class Private; // expected-note {{declared private here}}
+};
+
+struct Bar {};
+
+template <typename T>
+Foo::Private Bar::ABC; // expected-error {{no member named 'ABC' in 'NoCrashOnDelayedAccessCheck::Bar'}} \
+ expected-error {{'Private' is a private member of}}
+}
More information about the cfe-commits
mailing list