summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-04-17 22:30:01 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-04-17 22:30:01 +0000
commit87162c2e528921aabb84e96fe7272348a4b3354e (patch)
tree7971c636196449ca3e43c3fd017c43996a43fd4c
parent9591697707c69af99bb196d70895f4e7e28be333 (diff)
PR12569: Instantiate exception specifications of explicit instantiations
and explicit specializations of function templates appropriately. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154956 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp7
-rw-r--r--lib/Sema/SemaTemplateInstantiateDecl.cpp11
-rw-r--r--test/CodeGenCXX/cxx11-exception-spec.cpp64
-rw-r--r--test/SemaTemplate/instantiate-exception-spec-cxx11.cpp13
4 files changed, 84 insertions, 11 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index c7bd72b03e..1550993079 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -7185,8 +7185,7 @@ void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
}
}
-Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope,
- Declarator &D) {
+Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
assert(getCurFunctionDecl() == 0 && "Function parsing confused");
assert(D.isFunctionDeclarator() && "Not a function declarator!");
Scope *ParentScope = FnBodyScope->getParent();
@@ -7359,6 +7358,10 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
}
}
+ // Ensure that the function's exception specification is instantiated.
+ if (const FunctionProtoType *FPT = FD->getType()->getAs<FunctionProtoType>())
+ ResolveExceptionSpec(D->getLocation(), FPT);
+
// Checking attributes of current function definition
// dllimport attribute.
DLLImportAttr *DA = FD->getAttr<DLLImportAttr>();
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 39c27fc497..4d312f855f 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2377,7 +2377,16 @@ static void InstantiateExceptionSpec(Sema &SemaRef, FunctionDecl *New,
void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
FunctionDecl *Decl) {
- FunctionDecl *Tmpl = Decl->getTemplateInstantiationPattern();
+ // Find the template declaration which contains the exception specification.
+ // Per [except.spec]p4, prefer the exception spec on the primary template
+ // if this is an explicit instantiation.
+ FunctionDecl *Tmpl = 0;
+ if (Decl->getPrimaryTemplate())
+ Tmpl = Decl->getPrimaryTemplate()->getTemplatedDecl();
+ else if (FunctionDecl *MemTmpl = Decl->getInstantiatedFromMemberFunction())
+ Tmpl = MemTmpl;
+ else
+ Tmpl = Decl->getTemplateInstantiationPattern();
assert(Tmpl && "can't instantiate non-template");
if (Decl->getType()->castAs<FunctionProtoType>()->getExceptionSpecType()
diff --git a/test/CodeGenCXX/cxx11-exception-spec.cpp b/test/CodeGenCXX/cxx11-exception-spec.cpp
index 461af78eae..4e08dce2ae 100644
--- a/test/CodeGenCXX/cxx11-exception-spec.cpp
+++ b/test/CodeGenCXX/cxx11-exception-spec.cpp
@@ -1,18 +1,66 @@
-// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -verify -fexceptions -fcxx-exceptions -triple x86_64-linux-gnu | FileCheck %s
-template<typename T> void f() noexcept(sizeof(T) == 4);
+void h();
+
+template<typename T> void f() noexcept(sizeof(T) == 4) { h(); }
+
+template<typename T> struct S {
+ static void f() noexcept(sizeof(T) == 4) { h(); }
+};
+
+// CHECK: define {{.*}} @_Z1fIsEvv() {
+template<> void f<short>() { h(); }
+// CHECK: define {{.*}} @_Z1fIA2_sEvv() nounwind {
+template<> void f<short[2]>() noexcept { h(); }
+
+// CHECK: define {{.*}} @_ZN1SIsE1fEv()
+// CHECK-NOT: nounwind
+template<> void S<short>::f() { h(); }
+// CHECK: define {{.*}} @_ZN1SIA2_sE1fEv() nounwind
+template<> void S<short[2]>::f() noexcept { h(); }
+
+// CHECK: define {{.*}} @_Z1fIDsEvv() {
+template void f<char16_t>();
+// CHECK: define {{.*}} @_Z1fIA2_DsEvv() nounwind {
+template void f<char16_t[2]>();
+
+// CHECK: define {{.*}} @_ZN1SIDsE1fEv()
+// CHECK-NOT: nounwind
+template void S<char16_t>::f();
+// CHECK: define {{.*}} @_ZN1SIA2_DsE1fEv() nounwind
+template void S<char16_t[2]>::f();
void g() {
- // CHECK: declare void @_Z1fIiEvv() nounwind
+ // CHECK: define {{.*}} @_Z1fIiEvv() nounwind {
f<int>();
- // CHECK: declare void @_Z1fIA2_iEvv()
+ // CHECK: define {{.*}} @_Z1fIA2_iEvv() {
f<int[2]>();
- // CHECK: declare void @_Z1fIfEvv() nounwind
+
+ // CHECK: define {{.*}} @_ZN1SIiE1fEv() nounwind
+ S<int>::f();
+ // CHECK: define {{.*}} @_ZN1SIA2_iE1fEv()
+ // CHECK-NOT: nounwind
+ S<int[2]>::f();
+
+ // CHECK: define {{.*}} @_Z1fIfEvv() nounwind {
void (*f1)() = &f<float>;
- // CHECK: declare void @_Z1fIdEvv()
+ // CHECK: define {{.*}} @_Z1fIdEvv() {
void (*f2)() = &f<double>;
- // CHECK: declare void @_Z1fIA4_cEvv() nounwind
+
+ // CHECK: define {{.*}} @_ZN1SIfE1fEv() nounwind
+ void (*f3)() = &S<float>::f;
+ // CHECK: define {{.*}} @_ZN1SIdE1fEv()
+ // CHECK-NOT: nounwind
+ void (*f4)() = &S<double>::f;
+
+ // CHECK: define {{.*}} @_Z1fIA4_cEvv() nounwind {
(void)&f<char[4]>;
- // CHECK: declare void @_Z1fIcEvv()
+ // CHECK: define {{.*}} @_Z1fIcEvv() {
(void)&f<char>;
+
+ // CHECK: define {{.*}} @_ZN1SIA4_cE1fEv() nounwind
+ (void)&S<char[4]>::f;
+ // CHECK: define {{.*}} @_ZN1SIcE1fEv()
+ // CHECK-NOT: nounwind
+ (void)&S<char>::f;
}
diff --git a/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp b/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
index 763b9ed41b..d29c8862b9 100644
--- a/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
+++ b/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp
@@ -105,3 +105,16 @@ namespace core_19754_example {
base<types> val = base<types>();
}
+
+namespace pr9485 {
+ template <typename T> void f1(T) throw(typename T::exception); // expected-note {{candidate}}
+ template <typename T> void f1(T, int = 0) throw(typename T::noitpecxe); // expected-note {{candidate}}
+
+ template <typename T> void f2(T) noexcept(T::throws); // expected-note {{candidate}}
+ template <typename T> void f2(T, int = 0) noexcept(T::sworht); // expected-note {{candidate}}
+
+ void test() {
+ f1(0); // expected-error {{ambiguous}}
+ f2(0); // expected-error {{ambiguous}}
+ }
+}