aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2009-04-27 21:03:30 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2009-04-27 21:03:30 +0000
commitfef9f59e80275cc7515676ee6d8cc539ef155b47 (patch)
tree3e839f7411021b8bab0035e6f716f8f5a4dba1f2
parent972041f45bdf8df7ea447221292d7827466ba94b (diff)
Don't allow catch declarations to name an abstract class
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70248 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclCXX.cpp5
-rw-r--r--test/SemaCXX/exceptions.cpp3
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index bc87c6775a..87a518b558 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2577,6 +2577,11 @@ Sema::DeclPtrTy Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) {
RequireCompleteType(Begin, BaseType, DK))
Invalid = true;
+ if (!Invalid && RequireNonAbstractType(Begin, ExDeclType,
+ diag::err_abstract_type_in_decl,
+ AbstractVariableType))
+ Invalid = true;
+
// FIXME: Need to test for ability to copy-construct and destroy the
// exception variable.
// FIXME: Need to check for abstract classes.
diff --git a/test/SemaCXX/exceptions.cpp b/test/SemaCXX/exceptions.cpp
index 508f23d148..42973eba70 100644
--- a/test/SemaCXX/exceptions.cpp
+++ b/test/SemaCXX/exceptions.cpp
@@ -2,6 +2,8 @@
struct A; // expected-note 4 {{forward declaration of 'struct A'}}
+struct Abstract { virtual void f() = 0; }; // expected-note {{pure virtual function 'f'}}
+
void trys() {
try {
} catch(int i) { // expected-note {{previous definition}}
@@ -12,6 +14,7 @@ void trys() {
} catch(A a) { // expected-error {{cannot catch incomplete type 'struct A'}}
} catch(A *a) { // expected-error {{cannot catch pointer to incomplete type 'struct A'}}
} catch(A &a) { // expected-error {{cannot catch reference to incomplete type 'struct A'}}
+ } catch(Abstract) { // expected-error {{variable type 'Abstract' is an abstract class}}
} catch(...) {
int j = i; // expected-error {{use of undeclared identifier 'i'}}
}