From: Nikola Smiljanic Date: Sun, 24 Aug 2014 23:28:47 +0000 (+0000) Subject: PR20716 - Crash when recovering from type in known dependent base. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ed7bfbd4b52795baa6a6a11e7c59d991fb500ef;p=clang PR20716 - Crash when recovering from type in known dependent base. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216352 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 980a06e35b..7c0da8ff0c 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -236,7 +236,7 @@ protected: TemplateParams(nullptr) {} // Construct a template decl with the given name and parameters. - // Used when there is not templated element (tt-params, alias?). + // Used when there is not templated element (tt-params). TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params) : NamedDecl(DK, DC, L, Name), TemplatedDecl(nullptr), diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 0244d4c4a3..5293188214 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -152,7 +152,10 @@ static ParsedType recoverFromTypeInKnownDependentBase(Sema &S, auto *TD = TST->getTemplateName().getAsTemplateDecl(); if (!TD) continue; - auto *BasePrimaryTemplate = cast(TD->getTemplatedDecl()); + auto *BasePrimaryTemplate = + dyn_cast_or_null(TD->getTemplatedDecl()); + if (!BasePrimaryTemplate) + continue; // FIXME: Allow lookup into non-dependent bases of dependent bases, possibly // by calling or integrating with the main LookupQualifiedName mechanism. for (NamedDecl *ND : BasePrimaryTemplate->lookup(&II)) { diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 4bdb97bbbd..979782f1cb 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -470,3 +470,23 @@ void f() { UndefVar.method(); // expected-error {{use of undeclared identifier 'UndefVar'}} } } + +namespace PR20716 { +template