From 4c51174677306561eb4a18bb05b20cd3030d4b74 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Mon, 4 May 2015 16:44:39 +0000 Subject: Instantiate incomplete class used in template method. If a class is absent from instantiation and is incomplete, instantiate it as an incomplete class thus avoiding compiler crash. This change fixes PR18653. Differential Revision: http://reviews.llvm.org/D8281 llvm-svn: 236426 --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 5 +++++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'clang/lib') diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 62b506276e6..18747825537 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2788,6 +2788,11 @@ LocalInstantiationScope::findInstantiationOf(const Decl *D) { isa(D)) return nullptr; + // Tag type may be referenced prior to definition, in this case it does not + // have instantiation yet. + if (isa(D)) + return nullptr; + // If we didn't find the decl, then we either have a sema bug, or we have a // forward reference to a label declaration. Return null to indicate that // we have an uninstantiated label. diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 8f2e95a6152..41245d9b3fd 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4434,6 +4434,14 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, if (D->isInvalidDecl()) return nullptr; + // Tag type may be referenced prior to definition, in this case it must be + // instantiated now. + if (const TagDecl *TD = dyn_cast(D)) { + Decl *Inst = SubstDecl(D, CurContext, TemplateArgs); + CurrentInstantiationScope->InstantiatedLocal(D, Inst); + return cast(Inst); + } + // If we didn't find the decl, then we must have a label decl that hasn't // been found yet. Lazily instantiate it and return it now. assert(isa(D)); -- cgit v1.2.3