]> granicus.if.org Git - clang/commitdiff
[SemaTemplate] Detect instantiation of unparsed exceptions.
authorDavide Italiano <davide@freebsd.org>
Sat, 25 Jul 2015 01:19:32 +0000 (01:19 +0000)
committerDavide Italiano <davide@freebsd.org>
Sat, 25 Jul 2015 01:19:32 +0000 (01:19 +0000)
This fixes the clang crash reported in PR24000.

Differential Revision: http://reviews.llvm.org/D11341

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

lib/Sema/SemaExceptionSpec.cpp
test/SemaTemplate/crash-unparsed-exception.cpp [new file with mode: 0644]

index 8a9372336e88920ba9e8551ae4045740a9fed179..ec3d9fd82fe6c82a1ec4c7866149bde2bb579226 100644 (file)
@@ -161,7 +161,13 @@ Sema::ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT) {
   else
     InstantiateExceptionSpec(Loc, SourceDecl);
 
-  return SourceDecl->getType()->castAs<FunctionProtoType>();
+  const FunctionProtoType *Proto =
+    SourceDecl->getType()->castAs<FunctionProtoType>();
+  if (Proto->getExceptionSpecType() == clang::EST_Unparsed) {
+    Diag(Loc, diag::err_exception_spec_not_parsed);
+    Proto = nullptr;
+  }
+  return Proto;
 }
 
 void
diff --git a/test/SemaTemplate/crash-unparsed-exception.cpp b/test/SemaTemplate/crash-unparsed-exception.cpp
new file mode 100644 (file)
index 0000000..1226b35
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -fcxx-exceptions -fexceptions %s
+
+struct A {
+  virtual ~A();
+};
+template <class>
+struct B {};
+struct C {
+  template <typename>
+  struct D {
+    ~D() throw();
+  };
+  struct E : A {
+    D<int> d; //expected-error{{exception specification is not available until end of class definition}}
+  };
+  B<int> b; //expected-note{{in instantiation of template class 'B<int>' requested here}}
+};