Skip to content

Commit e56d1a0

Browse files
committed
[Sema] Don't permit catching variably modified types
Variably modified types shouldn't be permitted in catch clauses. This fixes PR28047. llvm-svn: 272159
1 parent a41272f commit e56d1a0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5904,6 +5904,8 @@ def err_catch_incomplete_ref : Error<
59045904
"cannot catch reference to incomplete type %0">;
59055905
def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
59065906
def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue reference">;
5907+
def err_catch_variably_modified : Error<
5908+
"cannot catch variably modified type %0">;
59075909
def err_qualified_catch_declarator : Error<
59085910
"exception declarator cannot be qualified">;
59095911
def err_early_catch_all : Error<"catch-all handler must come last">;

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12207,6 +12207,11 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S,
1220712207
Invalid = true;
1220812208
}
1220912209

12210+
if (ExDeclType->isVariablyModifiedType()) {
12211+
Diag(Loc, diag::err_catch_variably_modified) << ExDeclType;
12212+
Invalid = true;
12213+
}
12214+
1221012215
QualType BaseType = ExDeclType;
1221112216
int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference
1221212217
unsigned DK = diag::err_catch_incomplete;

clang/test/SemaCXX/exceptions.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,17 @@ void g() {
268268
}
269269
}
270270
}
271+
272+
namespace PR28047 {
273+
void test1(int i) {
274+
try {
275+
} catch (int(*)[i]) { // expected-error{{cannot catch variably modified type}}
276+
}
277+
}
278+
void test2() {
279+
int i;
280+
try {
281+
} catch (int(*)[i]) { // expected-error{{cannot catch variably modified type}}
282+
}
283+
}
284+
}

0 commit comments

Comments
 (0)