Cpp.InitializerList Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the initializer_list nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.InitializerList represents the node initializer_list in the syntax tree of your code.
int arr[] = {1, 2, 3};
struct S { int x; int y; };
S s = { .x = 1, .y = 2 };
int mat[2][2] = { {1, 2}, {3, 4} };The three brace-enclosed expressions in the code are initializer_list nodes and correspond to Cpp.InitializerList in PQL.
Predicates
| Type | Raisable | Printable |
|---|---|---|
InitializerList
| 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 InitializerList &initializerList)
| Matches an initializer_list node and returns it as the
output variable. | This PQL defect checks for any initializer list node in the translation unit. defect find_init_list =
when
Cpp.InitializerList.is(&il)
and il.nodeText(&txt)
raise "found initializer list: {txt}"
on ilIn this C++ code the defect finds each brace-enclosed
initializer like
int arr[] = {1, 2, 3}; |
cast(Cpp.Node.Node node, required InitializerList &cast)
| If the provided Node is an
initializer_list then returns it as an
InitializerList. | This PQL defect finds defect cast_node_to_init =
when
Cpp.Node.is(&node,&,&,&)
and Cpp.InitializerList.cast(node, &il)
and il.nodeText(&txt)
raise "casted node to initializer_list: {txt}"
on ilIn this C++ code the defect finds the initializer list.
int arr[] = {1, 2, 3}; |
isa(Cpp.Node.Node node)
| Tests whether the given Node is an
initializer_list. | This PQL defect checks whether a node is an initializer list and reports when it is not. defect not_init_list =
when
Cpp.Node.is(&node,&,&,&)
and not Cpp.InitializerList.isa(node)
raise "node is not an initializer_list"
on esIn this C++ code the defect checks finds all nodes that are not initializer lists.
int x = 5; |
expression(InitializerList self, Cpp.Node.Node &child)
| Matches each element expression contained directly in the initializer list. | This PQL defect checks for expression elements inside an initializer list. defect init_expr_elements =
when
Cpp.InitializerList.is(&il)
and il.expression(&elem)
and elem.nodeText(&txt)
raise "initializer element: {txt}"
on il |
initializerPair(InitializerList self, Cpp.Node.Node &child)
| Matches a designated initializer pair such as .field = value
inside an initializer list. | This PQL defect checks for designated initializer pairs inside a struct initializer. defect init_designators =
when
Cpp.InitializerList.is(&il)
and il.initializerPair(&pair)
and pair.nodeText(&txt)
raise "designated initializer pair: {txt}"
on ilIn this C++ code the defect finds
struct S { int x; int y; };
S s = { .x = 1, .y = 2 }; |
initializerList(InitializerList self, Cpp.Node.Node &child)
| Matches nested initializer_list nodes contained within
another initializer list. | This PQL defect checks for nested initializer lists such as for multidimensional arrays. defect nested_init_lists =
when
Cpp.InitializerList.is(&il)
and il.initializerList(&nested)
and nested.nodeText(&txt)
raise "nested initializer list: {txt}"
on ilIn this C++ code the defect finds the inner lists
int mat[2][2] = { {1, 2}, {3, 4} }; |
getEnclosingInitializerList(Cpp.Node.Node child, required InitializerList
&parent)
| Finds the nearest enclosing initializer_list ancestor of the
given node and returns it. | This PQL defect checks which initializer list encloses a generic expression node. defect find_enclosing_init =
when
Cpp.Node.is(&node,&,&,&)
and Cpp.InitializerList.getEnclosingInitializerList(node, &parent)
and parent.nodeText(&txt)
raise "enclosing initializer list: {txt}"
on parentIn this C++ code the defect finds an initializer list.
int arr[] = {1, 2, 3}; |
isEnclosedInInitializerList(Cpp.Node.Node child)
| Checks whether the given node has any initializer_list
ancestor. | This PQL defect checks whether a node appears inside any initializer list. defect check_enclosed_in_init =
when
Cpp.Node.is(&node,&,&,&)
and Cpp.InitializerList.isEnclosedInInitializerList(node)
and id.name(&nm)
raise "identifier '{nm}' is inside an initializer list"
on idIn this C++ code the defect finds all nodes enclosed by an initializer list.
struct S { int x; int y; };
S s = { .x = 1, .y = 2 }; |
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)