From 1503f777d94fc05a89c7305651d4b0221c63f586 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 31 Jul 2009 01:43:05 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaTemplate.cpp | 11 +++++------ test/SemaTemplate/nested-linkage.cpp | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 test/SemaTemplate/nested-linkage.cpp 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(); } } -- 2.40.0