diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9789609d5adb8896e29cb833d88e7beb79951417..1813544a78cfe56ff6d703b2539ef114320c9bfe 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8212bd4db3f77018263d50e26379a6aa9357d395..1ab3fb2ab86590978e201a2c8e94f3538312976f 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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; diff --git a/test/SemaCXX/exceptions.cpp b/test/SemaCXX/exceptions.cpp index 05793e2ffc84c7b62fdd1ddab3bb1e2a7b15714e..9e76783ca8a9e72d9109411137828ff086c5cacf 100644 --- a/test/SemaCXX/exceptions.cpp +++ b/test/SemaCXX/exceptions.cpp @@ -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}} + } +} +}