Cpp.GotoStatement Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the goto_statement nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.GotoStatement represents the node goto_statement in the syntax tree of your code.
void test_goto() {
goto myLabel;
myLabel:
return;
}The example defines a goto statement and a labeled statement. The goto myLabel; corresponds to the goto_statement node represented by Cpp.GotoStatement.
Predicates
| Type | Raisable | Printable |
|---|---|---|
GotoStatement
| 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 GotoStatement &gotoStatement)
| Matches a goto_statement node and binds it to the provided
output variable. Use this when you want to directly obtain a
Cpp.GotoStatement node. | This PQL defect checks for the presence of any
defect find_goto =
when
Cpp.GotoStatement.is(&gs)
and gs.nodeText(&txt)
raise "Found goto: \"{txt}\""
on gsIn this C++ code the defect finds the
#include <iostream>
void f() {
goto end;
std::cout << "never\n";
end:
return;
}
int main() { f(); } |
cast(Cpp.Node.Node node, required GotoStatement &cast)
| Checks whether a given generic Node is a
goto_statement and if so converts and binds it to
GotoStatement. Use this to refine a generic node to a
GotoStatement. | This PQL defect checks for nodes that are
defect cast_node_to_goto =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.GotoStatement.cast(n, &gs)
and gs.nodeText(&txt)
raise "Casted node is goto: \"{txt}\""
on gs |
isa(Cpp.Node.Node node)
| Returns true when the provided generic Node is a
goto_statement. Use this when you only need a boolean test or
want to negate the check. | This PQL defect checks whether a generic defect find_non_goto_node =
when
Cpp.Node.is(&n, &,&,&)
and not Cpp.GotoStatement.isa(n)
raise "Node is not a goto_statement"
on n |
label(GotoStatement self, Cpp.Node.Node &child)
| Binds the node that names the target label of the goto
statement. Use this to obtain the identifier node for the jump target. | This PQL defect checks for defect find_goto_label =
when
Cpp.GotoStatement.is(&gs)
and gs.label(&lbl)
and lbl.nodeText(&txt)
raise "Goto target label: \"{txt}\""
on gsIn this C++ code the defect extracts
void test() {
goto myLabel;
myLabel:
return;
}
int main() { test(); } |
getEnclosingGotoStatement(Cpp.Node.Node child, required GotoStatement
&parent)
| Finds the closest ancestor goto_statement for the provided
child node and binds it to parent. Use this
to relate inner nodes back to the surrounding goto
statement. | This PQL defect checks for a defect find_enclosing_goto =
when
Cpp.Identifier.is(&id)
and Cpp.GotoStatement.getEnclosingGotoStatement(id.toNode(&n), &gs)
and gs.nodeText(&txt)
raise "Enclosing goto found: \"{txt}\""
on gs |
isEnclosedInGotoStatement(Cpp.Node.Node child)
| Returns true if the provided child node has a
goto_statement ancestor. Use this to test whether a node lies
within the scope of a goto statement construct. | This PQL defect checks identifier nodes that are located inside any
defect node_within_goto =
when
Cpp.Identifier.is(&id)
and Cpp.GotoStatement.isEnclosedInGotoStatement(id.toNode(&n))
raise "Identifier is inside a goto statement context"
on idIn this C++ code the defect will identify identifiers
that are nested under a labeled statement reached by a
void k() {
goto L;
L:
int value = 42; // 'value' identifier is enclosed in the labeled statement reachable by goto
}
int main() { k(); } |
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)