Cpp.ReturnStatement Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the return_statement nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.ReturnStatement represents the node return_statement in the syntax tree of your code.
#include <vector>
int scalar() {
return 42;
}
int comma_expr() {
int a = 0, b = 0;
return (a++, b++);
}
std::vector<int> vec() {
return {1, 2, 3};
}The examples show three return statements. Each of these is
return_statement node matched by
Cpp.ReturnStatement.
Predicates
| Type | Raisable | Printable |
|---|---|---|
ReturnStatement
| 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 ReturnStatement &returnStatement)
| Matches a return_statement node and returns it as the output
variable. Use this to directly obtain the return node for further queries. | This PQL defect checks for any defect defectIs =
when
Cpp.ReturnStatement.is(&rs)
and rs.nodeText(&txt)
raise "ReturnStatement.is matched: \"{txt}\""
on rsIn this C++ code, the defect finds plain return statements such as returning a literal, an expression, or an initializer list.
int f1() { return 42; }
int f2() { int x=0; return (x++, x); }
std::vector<int> f3() { return {1,2}; } |
cast(Cpp.Node.Node node, required ReturnStatement &cast)
| Checks whether a generic Node is a
return_statement and if so returns that node to a
ReturnStatement variable. Use this to convert a
Node to a ReturnStatement when the node type
is uncertain. | This PQL defect checks for nodes that are
defect defectCast =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ReturnStatement.cast(node, &rs)
and rs.nodeText(&txt)
raise "ReturnStatement.cast matched: \"{txt}\""
on rsIn this C++ code, the defect finds a return statement among the generic syntax nodes.
int g() { return 42; } |
isa(Cpp.Node.Node node)
| Tests whether a given Node is a
return_statement. Use this for boolean checks or negation
patterns. | This PQL defect checks that a rule CheckIsa = { defectIsa }
defect defectIsa =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ReturnStatement.isa(node)
raise "Node is a ReturnStatement"
on nodeIn this C++ code, the defect finds a return statement among the generic syntax nodes.
int h() { return 0; } |
commaExpression(ReturnStatement self, Cpp.Node.Node &child)
| Matches a child comma_expression inside the return statement
and returns that child node. Use it to detect returns that use the comma
operator. | This PQL defect checks for defect defectCommaExpression =
when
Cpp.ReturnStatement.is(&rs)
and rs.commaExpression(&ce)
and ce.nodeText(&txt)
raise "ReturnStatement.commaExpression matched: \"{txt}\""
on rsIn this C++ code, the defect finds
int k() {
int a=0,b=0;
return (a++, b++);
} |
initializerList(ReturnStatement self, Cpp.Node.Node &child)
| Matches an initializer_list child inside the return
statement and returns that child node. Use it to detect returns that use braced
initializer lists. | This PQL defect checks for defect defectInitializerList =
when
Cpp.ReturnStatement.is(&rs)
and rs.initializerList(&il)
and il.nodeText(&txt)
raise "ReturnStatement.initializerList matched: \"{txt}\""
on rsIn this C++ code, the defect finds
#include <vector>
std::vector<int> v() {
return {1, 2, 3};
} |
expression(ReturnStatement self, Cpp.Node.Node &child)
| Matches a general expression child inside the return
statement and returns that child. Use it to capture typical return expressions like
literals or variables. | This PQL defect checks for defect defectExpression =
when
Cpp.ReturnStatement.is(&rs)
and rs.expression(&expr)
and expr.nodeText(&txt)
raise "ReturnStatement.expression matched: \"{txt}\""
on rsIn this C++ code, the defect finds
int m() { return 42; } |
getEnclosingReturnStatement(Cpp.Node.Node child, required ReturnStatement
&parent)
| Finds the nearest ancestor return_statement for a given
child Node and returns that ancestor. Use it to locate the return
that contains a specific subnode. | This PQL defect checks for a defect defectEnclosing =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ReturnStatement.getEnclosingReturnStatement(node, &rs)
and rs.nodeText(&txt)
raise "Enclosing ReturnStatement: \"{txt}\""
on rsIn this C++ code, the defect finds the
int n() {
int a=0,b=0;
return (a++, b++);
} |
isEnclosedInReturnStatement(Cpp.Node.Node child)
| Tests whether a given Node has a
return_statement ancestor. Use this to check if a node appears
inside a return. | This PQL defect checks whether a node is located inside any
defect defectIsEnclosed =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ReturnStatement.isEnclosedInReturnStatement(node)
raise "Node is enclosed in a ReturnStatement"
on nodeIn this C++ code, the defect confirms that the
comma operator subexpression or a literal is inside a
int p() {
int a=0,b=0;
return (a++, b++);
} |
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)