From: David Majnemer Date: Thu, 15 Jan 2015 07:04:38 +0000 (+0000) Subject: Sema: Recover when a function template is in an extern "C" block X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0d42e35eccaf761ffa7aec0a641c2493a48f0693;p=clang Sema: Recover when a function template is in an extern "C" block git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226135 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 007470344f..9b9a6afbfd 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7010,12 +7010,12 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Check that we can declare a template here. if (CheckTemplateDeclScope(S, TemplateParams)) - return nullptr; + NewFD->setInvalidDecl(); // A destructor cannot be a template. if (Name.getNameKind() == DeclarationName::CXXDestructorName) { Diag(NewFD->getLocation(), diag::err_destructor_template); - return nullptr; + NewFD->setInvalidDecl(); } // If we're adding a template to a dependent context, we may need to diff --git a/test/SemaCXX/cxx0x-defaulted-functions.cpp b/test/SemaCXX/cxx0x-defaulted-functions.cpp index bc03bcd2a1..617a257163 100644 --- a/test/SemaCXX/cxx0x-defaulted-functions.cpp +++ b/test/SemaCXX/cxx0x-defaulted-functions.cpp @@ -173,7 +173,7 @@ namespace PR14577 { extern "C" { template // expected-error {{templates must have C++ linkage}} - void PR13573(const _Tp&) = delete; // expected-error {{only functions can have deleted definitions}} + void PR13573(const _Tp&) = delete; } namespace PR15597 { diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index c67361bfea..4f861dea70 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -146,3 +146,9 @@ namespace redecl { }; }; } + +extern "C" template // expected-error{{templates must have C++ linkage}} +void DontCrashOnThis() { + T &pT = T(); + pT; +} diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp index 4e1af9ad1f..853ba492f8 100644 --- a/test/SemaTemplate/destructor-template.cpp +++ b/test/SemaTemplate/destructor-template.cpp @@ -52,9 +52,13 @@ namespace PR7239 { } namespace PR7904 { - struct Foo { - template ~Foo() {} // expected-error{{destructor cannot be declared as a template}} - }; + struct Foo {}; + template + Foo::~Foo() { // expected-error{{destructor cannot be declared as a template}} + T t; + T &pT = t; + pT; + } Foo f; }