Cpp.CompoundLiteralExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the compound_literal_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class CompoundLiteralExpression represents the node compound_literal_expression in the syntax tree of your code.
struct S { int x, y; };
void demo() {
S a = (S){1, 2};
S b = (S){ .x = 3, .y = 4 }; // GNU extension-style compound literals
}The two initializer expressions (S){1, 2} and (S){ .x = 3, .y = 4 } correspond to compound_literal_expression nodes matched by the CompoundLiteralExpression PQL class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
CompoundLiteralExpression
| 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 CompoundLiteralExpression &cle)
| Matches nodes that are compound_literal_expression and returns the node as &cle for further predicates. |
This PQL defect checks for any defect find_compound_literals =
when
Cpp.CompoundLiteralExpression.is(&cle)
and cle.nodeText(&txt)
raise "Found compound literal: \"{txt}\""
on cleIn this C++ code, the defect checks for the presence of compound literal expressions such as
struct S { int x, y; };
void f() {
S s = (S){1, 2};
} |
cast(Cpp.Node.Node node, required CompoundLiteralExpression &cast)
| If node is a compound_literal_expression, this predicate returns it as &cast so you can operate on it from a generic Cpp.Node. | This PQL defect checks whether a generic defect cast_to_compound =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CompoundLiteralExpression.cast(node, &cle)
and cle.nodeText(&txt)
raise "Node is compound literal: \"{txt}\""
on cleIn this C++ code, the defect filters the generic node
that can be cast into a compound literal expression and finds the expression
struct S { int x, y; };
void g() {
auto t = (S){ .x = 3, .y = 4 };
} |
isa(Cpp.Node.Node node)
| Returns true when node is a
compound_literal_expression; useful for conditional checks or
negation. | This PQL defect checks generic nodes and filters them by whether they are
defect isa_compound_check =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CompoundLiteralExpression.isa(node)
raise "Node is a compound literal"
on nodeIn this C++ code, the defect identifies that
struct S { int x, y; };
void h() {
S s = (S){1, 2};
} |
type(CompoundLiteralExpression self, Cpp.Node.Node &child)
| Matches the type portion of a compound literal and returns that node as
&child. |
This PQL defect checks for the type component inside defect compound_type =
when
Cpp.CompoundLiteralExpression.is(&cle)
and cle.type(&typ)
and typ.nodeText(&txt)
raise "Compound literal type: \"{txt}\""
on cleIn this C++ code, the defect extracts the type token
struct S { int x, y; };
void k() {
S s = (S){1, 2};
} |
value(CompoundLiteralExpression self, Cpp.Node.Node &child)
| Matches the value part of the compound literal and returns it as
&child. | This PQL defect checks for the value node contained within a
defect compound_value =
when
Cpp.CompoundLiteralExpression.is(&cle)
and cle.value(&val)
and val.nodeText(&txt)
raise "Compound literal value: \"{txt}\""
on cleIn this C++ code, the defect captures the
initializer
struct S { int x, y; };
void m() {
S s = (S){1, 2};
} |
getEnclosingCompoundLiteralExpression(Cpp.Node.Node child, required CompoundLiteralExpression &parent)
| Finds the nearest enclosing compound_literal_expression ancestor for the given child node and returns it as &parent. | This PQL defect identifies syntax nodes that are enclosed in a
defect enclosing_compound =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CompoundLiteralExpression.getEnclosingCompoundLiteralExpression(node, &cle)
and cle.nodeText(&txt)
raise "Identifier inside compound literal; enclosing: \"{txt}\""
on nodeIn this C++ code, the defect finds the nodes that
are children of a
struct S { int x, y; };
void n() {
S s = (S){ .x = 3, .y = 4 }; //match
} |
isEnclosedInCompoundLiteralExpression(Cpp.Node.Node child)
| True when the child node has any compound_literal_expression ancestor; useful to detect expressions nested inside compound literals. | This PQL defect checks whether number literal appears as a descendent of
a
defect inside_compound_check =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.NumberLiteral.isa(node)
and Cpp.CompoundLiteralExpression.isEnclosedInCompoundLiteralExpression(node)
raise "node is inside a compound literal"
on nodeIn this C++ code, the defect finds number literal
nodes that are descendent nodes of a
struct S { int x, y; };
void p() {
S s = (S){1, 2}; // numeric literals 1 and 2 are enclosed in a compound literal
} |
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)