Skip to content

Commit

Permalink
[Sema] Don't permit catching variably modified types
Browse files Browse the repository at this point in the history
Variably modified types shouldn't be permitted in catch clauses.

This fixes PR28047.

llvm-svn: 272159
  • Loading branch information
majnemer committed Jun 8, 2016
1 parent a41272f commit e56d1a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -5904,6 +5904,8 @@ def err_catch_incomplete_ref : Error<
"cannot catch reference to incomplete type %0">;
def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue reference">;
def err_catch_variably_modified : Error<
"cannot catch variably modified type %0">;
def err_qualified_catch_declarator : Error<
"exception declarator cannot be qualified">;
def err_early_catch_all : Error<"catch-all handler must come last">;
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12207,6 +12207,11 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S,
Invalid = true;
}

if (ExDeclType->isVariablyModifiedType()) {
Diag(Loc, diag::err_catch_variably_modified) << ExDeclType;
Invalid = true;
}

QualType BaseType = ExDeclType;
int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference
unsigned DK = diag::err_catch_incomplete;
Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaCXX/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,17 @@ void g() {
}
}
}

namespace PR28047 {
void test1(int i) {
try {
} catch (int(*)[i]) { // expected-error{{cannot catch variably modified type}}
}
}
void test2() {
int i;
try {
} catch (int(*)[i]) { // expected-error{{cannot catch variably modified type}}
}
}
}

0 comments on commit e56d1a0

Please sign in to comment.