[PATCH] D91380: [clang] Fix an assertion crash in delayed access check.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 12 12:38:13 PST 2020
hokein created this revision.
hokein added a reviewer: adamcz.
Herald added a project: clang.
hokein requested review of this revision.
TD-getTemplatedDecl() might not be a DeclContext variant, which can
trigger an assertion inside `isa<>`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91380
Files:
clang/lib/Sema/SemaAccess.cpp
clang/test/SemaCXX/cxx14-access.cpp
Index: clang/test/SemaCXX/cxx14-access.cpp
===================================================================
--- /dev/null
+++ 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}}
+}
Index: clang/lib/Sema/SemaAccess.cpp
===================================================================
--- clang/lib/Sema/SemaAccess.cpp
+++ clang/lib/Sema/SemaAccess.cpp
@@ -1476,7 +1476,8 @@
} 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91380.304937.patch
Type: text/x-patch
Size: 1119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201112/d5224eb2/attachment.bin>
More information about the cfe-commits
mailing list