From: Eli Friedman Date: Fri, 31 Jul 2009 01:43:05 +0000 (+0000) Subject: Make the check for the linkage of a template handle the case of nested X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1503f777d94fc05a89c7305651d4b0221c63f586;p=clang Make the check for the linkage of a template handle the case of nested linkage specifications correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77653 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 4264f32e9d..29258575c1 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2123,13 +2123,12 @@ Sema::CheckTemplateDeclScope(Scope *S, // A template-declaration can appear only as a namespace scope or // class scope declaration. DeclContext *Ctx = static_cast(S->getEntity()); - while (Ctx && isa(Ctx)) { - if (cast(Ctx)->getLanguage() != LinkageSpecDecl::lang_cxx) - return Diag(TemplateLoc, diag::err_template_linkage) - << TemplateRange; - + if (Ctx && isa(Ctx) && + cast(Ctx)->getLanguage() != LinkageSpecDecl::lang_cxx) + return Diag(TemplateLoc, diag::err_template_linkage) << TemplateRange; + + while (Ctx && isa(Ctx)) Ctx = Ctx->getParent(); - } if (Ctx && (Ctx->isFileContext() || Ctx->isRecord())) return false; diff --git a/test/SemaTemplate/nested-linkage.cpp b/test/SemaTemplate/nested-linkage.cpp new file mode 100644 index 0000000000..ffe9adc927 --- /dev/null +++ b/test/SemaTemplate/nested-linkage.cpp @@ -0,0 +1,3 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +extern "C" { extern "C++" { template C x(); } }