Clang error: cannot catch variably modified type A (err_catch_variably_modified)
Jump to navigation
Jump to search
Text | error: cannot catch variably modified type A |
---|---|
Type | Error |
Category | Semantic Issue |
Internal Id | err_catch_variably_modified |
Internal Message | cannot catch variably modified type %0
|
Regular Expression | (?:error|fatal error)\: cannot catch variably modified type (.*?)
|
First Commit | 2016-06-08 e56d1a0d5000 [Sema] Don't permit catching variably modified types |
Description
Example
Flags | -xc++ -fexceptions
|
|
---|---|---|
Source |
int main() {
int n = 10; // n modifies type variably
typedef int (*a)[n]; // a is a pointer to a VLA
try {
throw 20; // Throwing exception
} catch(a) { // Cannot catch a VLA pointer
// handle
}
return 0;
}
| |
Compiler Output |
<source>:8:14: error: cannot catch variably modified type 'a' (aka 'int (*)[n]') |
Clang Internals (17.0.6)
Git Commit Message
[Sema] Don't permit catching variably modified types Variably modified types shouldn't be permitted in catch clauses. This fixes PR28047. llvm-svn: 272159
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDeclCXX.cpp (line 16627)
/// Perform semantic analysis for the variable declaration that
/// occurs within a C++ catch clause, returning the newly-created
/// variable.
VarDecl *Sema::BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, SourceLocation StartLoc, SourceLocation Loc, IdentifierInfo *Name) {
// ...
if (ExDeclType->isVariablyModifiedType()) {
Diag(Loc, diag::err_catch_variably_modified) << ExDeclType;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaCXX/exceptions.cpp
- clang/test/SemaCXX/exceptions.cpp:281:17: error: cannot catch variably modified type 'int (*)[i]'
- clang/test/SemaCXX/exceptions.cpp:287:17: error: cannot catch variably modified type 'int (*)[i]'