]> granicus.if.org Git - clang/commitdiff
Make the check for the linkage of a template handle the case of nested
authorEli Friedman <eli.friedman@gmail.com>
Fri, 31 Jul 2009 01:43:05 +0000 (01:43 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 31 Jul 2009 01:43:05 +0000 (01:43 +0000)
linkage specifications correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77653 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp
test/SemaTemplate/nested-linkage.cpp [new file with mode: 0644]

index 4264f32e9d40676201cba46095d292486f38ec00..29258575c1cfa97c2e8be4eb31cc4fc89f764437 100644 (file)
@@ -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<DeclContext *>(S->getEntity());
-  while (Ctx && isa<LinkageSpecDecl>(Ctx)) {
-    if (cast<LinkageSpecDecl>(Ctx)->getLanguage() != LinkageSpecDecl::lang_cxx)
-      return Diag(TemplateLoc, diag::err_template_linkage)
-        << TemplateRange;
-
+  if (Ctx && isa<LinkageSpecDecl>(Ctx) &&
+      cast<LinkageSpecDecl>(Ctx)->getLanguage() != LinkageSpecDecl::lang_cxx)
+    return Diag(TemplateLoc, diag::err_template_linkage) << TemplateRange;
+  
+  while (Ctx && isa<LinkageSpecDecl>(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 (file)
index 0000000..ffe9adc
--- /dev/null
@@ -0,0 +1,3 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+extern "C" { extern "C++" { template<class C> C x(); } }