]> granicus.if.org Git - clang/commitdiff
Sema: Recover when a function template is in an extern "C" block
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 15 Jan 2015 07:04:38 +0000 (07:04 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 15 Jan 2015 07:04:38 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226135 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/cxx0x-defaulted-functions.cpp
test/SemaTemplate/class-template-decl.cpp
test/SemaTemplate/destructor-template.cpp

index 007470344f1969737579491c8908b8d71108fe72..9b9a6afbfd8fd8fdfc5fe1a9c497f8736065377b 100644 (file)
@@ -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 
index bc03bcd2a137702290202c881e965187fceca4b6..617a25716314b5735f80c4755d044c7b7d5955e5 100644 (file)
@@ -173,7 +173,7 @@ namespace PR14577 {
 
 extern "C" {
  template<typename _Tp> // 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 {
index c67361bfeafb5a48c97c066f7571cd7a800857e1..4f861dea70586d0e77339dc35f6643866cdd42b1 100644 (file)
@@ -146,3 +146,9 @@ namespace redecl {
     };
   };
 }
+
+extern "C" template <typename T> // expected-error{{templates must have C++ linkage}}
+void DontCrashOnThis() {
+  T &pT = T();
+  pT;
+}
index 4e1af9ad1f96579c275b3cc2d27676029514466a..853ba492f8e751ce3a6af1c5ab80302f811fc364 100644 (file)
@@ -52,9 +52,13 @@ namespace PR7239 {
 }
 
 namespace PR7904 {
-  struct Foo {
-    template <int i> ~Foo() {} // expected-error{{destructor cannot be declared as a template}}
-  };
+  struct Foo {};
+  template <class T>
+  Foo::~Foo() { // expected-error{{destructor cannot be declared as a template}}
+    T t;
+    T &pT = t;
+    pT;
+  }
   Foo f;
 }