Cpp.DeleteExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the delete_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class DeleteExpression represents the node delete_expression in the syntax tree of your code.
// example demonstrating delete_expression nodes
#include <iostream>
void f() {
int *p = new int(42);
delete p; // delete_expression (non-array)
int *a = new int[10];
delete[] a; // delete_expression (array form)
}The two delete statements correspond to delete_expression nodes; the single-object form (delete p) and array form (delete[] a) are both matched by DeleteExpression.
Predicates
| Type | Raisable | Printable |
|---|---|---|
DeleteExpression
| 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 DeleteExpression &de)
| Matches a delete_expression node and returns it as de; use this to directly select delete operations. |
This PQL defect checks for any defect find_delete =
when
Cpp.DeleteExpression.is(&de)
and de.nodeText(&txt)
raise "Found delete expression: {txt}"
on deIn this C++ code, the defect finds both the single-object and array
#include <cstdlib>
int main() {
int *p = new int;
delete p;
int *a = new int[5];
delete[] a;
return 0;
} |
cast(Cpp.Node.Node node, required DeleteExpression &cast)
| Checks whether a generic Cpp.Node.Node is a delete_expression; if yes, returns it as cast. Useful when you start from a generic node and need delete-specific queries. |
This PQL defect checks whether a given general node is a defect cast_to_delete =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.DeleteExpression.cast(node, &de)
and de.nodeText(&txt)
raise "Node is a delete expression: {txt}"
on deIn this C++ code, the defect identifies the node corresponding to
#include <memory>
struct S {
void g() {
int *p = new int;
delete p;
}
};
int main() { S s; s.g(); } |
isa(Cpp.Node.Node node)
| Returns true when the provided generic node is a delete_expression (boolean check); use it for presence/absence tests or negation. |
This PQL defect checks nodes to see if they are defect is_delete_bool =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.DeleteExpression.isa(n)
and n.nodeText(&txt)
raise "isa confirms delete_expression: {txt}"
on nIn this C++ code, the
int main() {
int *a = new int[3];
delete[] a;
return 0;
} |
expression(DeleteExpression self, Cpp.Node.Node &child)
| Retrieves the operand expression inside the delete (the thing being deleted), e.g., the pointer expression. |
This PQL defect checks for the operand expression used in a defect delete_operand =
when
Cpp.DeleteExpression.is(&de)
and de.expression(&expr)
and expr.nodeText(&txt)
raise "Delete operand text: {txt}"
on deIn this C++ code, the defect extracts the identifier
#include <iostream>
void demo() {
int *p = new int(7);
delete p; // operand is 'p'
}
int main(){ demo(); } |
getEnclosingDeleteExpression(Cpp.Node.Node child, required DeleteExpression &parent)
| Finds the nearest surrounding delete_expression that encloses the given child node; useful when you start from a subnode (e.g., an identifier) and need the enclosing delete. | This PQL defect checks for the closest
defect enclosing_delete =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.DeleteExpression.getEnclosingDeleteExpression(node, &de)
and node.nodeText(&iname)
and de.nodeText(&dtext)
raise "Node {iname} is inside delete: {dtext}"
on idIn this C++ code, the defect finds a delete expression that encloses a generic syntax node.
int main() {
int *p = new int;
delete p; // identifier 'p' is enclosed by this delete_expression
return 0;
} |
isEnclosedInDeleteExpression(Cpp.Node.Node child)
| Returns true if the given node has any delete_expression ancestor; use this to detect code elements that appear within a delete operation. | This PQL defect checks whether a node appears inside a
defect inside_delete_check =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.DeleteExpression.isEnclosedInDeleteExpression(node)
and node.nodeText(&txt)
raise "Identifier {txt} is inside a delete expression"
on idIn this C++ code, the defect identifies all syntax nodes that are descendent of a delete expression.
int main() {
int *a = new int[4];
delete[] a; // 'a' is enclosed in a delete_expression
return 0;
} |
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)