Cpp.CaseStatement Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the case_statement nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.CaseStatement represents the node case_statement in the syntax tree of your code.
// Demonstrates multiple case_statement forms
#include <vector>
int f(int x, std::vector<int> v) {
switch(x) {
case 42: return 1;
case 1: { x = 2; break; }
case 2: for (auto &e : v) x += e;
case 3: co_yield 7; // requires coroutine support, illustrative
}
return 0;
}The switch arms case 42:, case 1: { ... }, case 2: ... and case 3: co_yield 7; are all case_statement nodes matched by Cpp.CaseStatement.
Predicates
| Type | Raisable | Printable |
|---|---|---|
CaseStatement
| Yes | No |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required CaseStatement &caseStatement)
| Matches the current syntax node when it is a case_statement
and returns it as caseStatement for further predicates. | This PQL defect checks for any defect check_case_is =
when
Cpp.CaseStatement.is(&case)
raise "Found a case statement"
on caseIn this C++ code, the defect finds each
int g(int x) {
switch(x) {
case 0: return 0;
case 1: return 1;
}
} |
cast(Cpp.Node.Node node, required CaseStatement &cast)
| Checks whether a given Node is a
case_statement and if so returns it as cast
for property queries. | This PQL defect checks nodes converted from another node type and
identifies those that are
defect check_case_cast =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.CaseStatement.cast(n, &case)
raise "Switch child is a case_statement"
on caseIn this C++ code, the defect finds cast statements
using
int h(int x) {
switch(x) {
case 5: x++; break;
}
return x;
} |
isa(Cpp.Node.Node node)
| Returns true when the provided Node is a
case_statement and can be used in negation or filters. | This PQL defect checks whether an arbitrary defect check_case_isa =
when
Cpp.Node.is(&node,&,&,&)
and Cpp.CaseStatement.isa(node)
raise "Node is a case_statement"
on nodeIn this C++ code, the defect scans all syntax
nodes and reports those that are
void k(int x) {
switch(x) {
case 9: x = 0;
}
} |
value(CaseStatement self, Cpp.Node.Node &child)
| Matches the constant or label expression of the case (the
expression after case) and returns it as a
Node. | This PQL defect checks for defect check_case_value =
when
Cpp.CaseStatement.is(&case)
and case.value(&val)
and val.nodeText(&txt)
and txt == "42"
raise "Case with value 42"
on caseIn this C++ code, the defect finds the
int m(int x) {
switch(x) {
case 42: return 1;
}
return 0;
} |
coYield(CaseStatement self, Cpp.Node.Node &child)
| Matches a coroutine co_yield statement appearing as the
case body and binds that statement node. | This PQL defect checks for defect check_case_coyield =
when
Cpp.CaseStatement.is(&case)
and case.coYield(&stmt)
raise "Case contains co_yield"
on caseIn this C++ code, the defect finds a
// Illustrative coroutine syntax; may require C++20 compiler settings
#include <coroutine>
int n(int x) {
switch(x) {
case 1: co_yield 10;
}
return 0;
} |
compound(CaseStatement self, Cpp.Node.Node &child)
| Matches a compound statement { ... } used as the
case body and returns it as a node. | This PQL defect checks for defect check_case_compound =
when
Cpp.CaseStatement.is(&case)
and case.compound(&)
raise "Case contains compound statement"
on caseIn this C++ code, the defect detects
int p(int x) {
switch(x) {
case 2: { x = 5; }
}
return x;
} |
continueStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a continue; statement inside a
case and binds that statement node. | This PQL defect checks for defect check_case_continue =
when
Cpp.CaseStatement.is(&case)
and case.continueStatement(&)
raise "Case contains continue"
on caseIn this C++ code, the defect finds a
int q(int x) {
switch(x) {
case 3: continue; // ill-formed outside loop but syntactically present
}
return x;
} |
declaration(CaseStatement self, Cpp.Node.Node &child)
| Matches a declaration statement (e.g., int y = 5;) inside a
case and returns it. | This PQL defect checks for defect check_case_decl =
when
Cpp.CaseStatement.is(&case)
and case.declaration(&)
raise "Case contains declaration"
on caseIn this C++ code, the defect locates
int r(int x) {
switch(x) {
case 4: int y = 5; return y;
}
return 0;
} |
doStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a do { ... } while(...) statement inside a
case and returns it. | This PQL defect checks for defect check_case_do =
when
Cpp.CaseStatement.is(&case)
and case.doStatement(&)
raise "Case contains do-while"
on caseIn this C++ code, the defect finds a
int s(int x) {
switch(x) {
case 5:
do { x++; } while (x < 10);
break;
}
return x;
} |
exprStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches an expression statement like x = 7; inside a
case and returns it. | This PQL defect checks for defect check_case_exprstmt =
when
Cpp.CaseStatement.is(&case)
and case.exprStatement(&)
raise "Case contains expression statement"
on caseIn this C++ code, the defect identifies
int t(int x) {
switch(x) {
case 6: x = 7; break;
}
return x;
} |
forRangeLoop(CaseStatement self, Cpp.Node.Node &child)
| Matches a range-based for loop (for (auto v :
vec)) inside a case and returns it. | This PQL defect checks for defect check_case_for_range =
when
Cpp.CaseStatement.is(&case)
and case.forRangeLoop(&)
raise "Case contains range-for"
on caseIn this C++ code, the defect finds
#include <vector>
int u(int x, std::vector<int> v) {
switch(x) {
case 7:
for (auto &e : v) x += e;
break;
}
return x;
} |
forStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a classic for loop (for(init; cond;
inc)) inside a case and returns it. | This PQL defect checks for defect check_case_for =
when
Cpp.CaseStatement.is(&case)
and case.forStatement(&)
raise "Case contains for-loop"
on caseIn this C++ code, the defect finds a
int v(int x) {
switch(x) {
case 8:
for (int i = 0; i < 3; ++i) x += i;
break;
}
return x;
} |
gotoStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a goto statement inside a case
and binds that statement node. | This PQL defect checks for defect check_case_goto =
when
Cpp.CaseStatement.is(&case)
and case.gotoStatement(&)
raise "Case contains goto"
on caseIn this C++ code, the defect detects a
int w(int x) {
switch(x) {
case 9: goto label;
}
label:
return x;
} |
ifStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches an if statement inside a case and
returns it. | This PQL defect checks for defect check_case_if =
when
Cpp.CaseStatement.is(&case)
and case.ifStatement(&)
raise "Case contains if"
on caseIn this C++ code, the defect finds
int xfunc(int x) {
switch(x) {
case 10:
if (x > 0) x--;
break;
}
return x;
} |
labeledStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a labeled statement like mylabel: stmt inside a
case and returns it. | This PQL defect checks for defect check_case_label =
when
Cpp.CaseStatement.is(&case)
and case.labeledStatement(&)
raise "Case contains labeled statement"
on caseIn this C++ code, the defect identifies an
explicit label inside a
int yfunc(int x) {
switch(x) {
case 11:
mylabel: x++;
break;
}
return x;
} |
returnStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a return statement inside a case
and returns it. | This PQL defect checks for defect check_case_return =
when
Cpp.CaseStatement.is(&case)
and case.returnStatement(&)
raise "Case contains return"
on caseIn this C++ code, the defect finds
int zfunc(int x) {
switch(x) {
case 12: return 0;
}
return 1;
} |
sehLeaveStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches MSVC SEH __leave; inside a case
and returns it. | This PQL defect checks for defect check_case_seh_leave =
when
Cpp.CaseStatement.is(&case)
and case.sehLeaveStatement(&)
raise "Case contains __leave"
on caseIn this C++ code, the defect locates
int a(int x) {
switch(x) {
case 13: __leave;
}
return 0;
} |
sehTryStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches MSVC SEH __try { ... } __except(...) { ... } inside
a case and returns it. | This PQL defect checks for defect check_case_seh_try =
when
Cpp.CaseStatement.is(&case)
and case.sehTryStatement(&)
raise "Case contains SEH try/except"
on caseIn this C++ code, the defect finds
int b(int x) {
switch(x) {
case 14: __try { x++; } __except(1) { x--; }
}
return x;
} |
switchStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a nested switch statement inside a
case and returns it. | This PQL defect checks for defect check_case_switch =
when
Cpp.CaseStatement.is(&case)
and case.switchStatement(&)
raise "Case contains nested switch"
on caseIn this C++ code, the defect finds a nested
int c(int x, int y) {
switch(x) {
case 15:
switch(y) { case 1: break; }
break;
}
return 0;
} |
throwStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a throw expression inside a case
and returns it. | This PQL defect checks for defect check_case_throw =
when
Cpp.CaseStatement.is(&case)
and case.throwStatement(&)
raise "Case contains throw"
on caseIn this C++ code, the defect finds
#include <stdexcept>
int d(int x) {
switch(x) {
case 16: throw std::runtime_error("err");
}
return 0;
} |
tryStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a C++ try { ... } catch(...) { ... } inside a
case and returns it. | This PQL defect checks for defect check_case_try =
when
Cpp.CaseStatement.is(&case)
and case.tryStatement(&)
raise "Case contains try/catch"
on caseIn this C++ code, the defect locates a
int e(int x) {
switch(x) {
case 17:
try { x++; } catch(...) { x--; }
break;
}
return x;
} |
typeDef(CaseStatement self, Cpp.Node.Node &child)
| Matches a typedef declaration inside a
case and returns it. | This PQL defect checks for defect check_case_typedef =
when
Cpp.CaseStatement.is(&case)
and case.typeDef(&)
raise "Case contains typedef"
on caseIn this C++ code, the defect finds
int f2(int x) {
switch(x) {
case 18: typedef int myint; break;
}
return 0;
} |
whileStatement(CaseStatement self, Cpp.Node.Node &child)
| Matches a while loop inside a case and
returns it. | This PQL defect checks for defect check_case_while =
when
Cpp.CaseStatement.is(&case)
and case.whileStatement(&)
raise "Case contains while"
on caseIn this C++ code, the defect finds
int g2(int x) {
switch(x) {
case 19: while (x < 100) ++x;
}
return x;
} |
attributedStatement(CaseStatement self, Cpp.Node.Node &child)
|
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)