Cpp.FieldDeclaration Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the field_declaration nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.FieldDeclaration represents the node field_declaration in the syntax tree of your code.
struct S {
int x = 42;
[[nodiscard]] int y;
virtual int z;
int w : 3;
__declspec(align(16)) int a;
static const int b = 1;
[[deprecated]] int d;
};The struct members like int x = 42; and [[nodiscard]] int y; correspond to field_declaration nodes that Cpp.FieldDeclaration models.
Predicates
| Type | Raisable | Printable |
|---|---|---|
FieldDeclaration
| 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 FieldDeclaration &fieldDeclaration)
| Matches a field_declaration node and returns it as the
output variable. Use this to select field declarations directly. | This PQL defect checks for any defect detect_field =
when
Cpp.FieldDeclaration.is(&fd)
and fd.nodeText(&txt)
raise "Found field: {txt}"
on fdIn this C++ code the defect finds each member
declaration such as
struct S {
int x = 42;
}; |
cast(Cpp.Node.Node node, required FieldDeclaration &cast)
| Checks whether a generic Node is a
field_declaration and returns it as a
FieldDeclaration when true. | This PQL defect checks nodes discovered as generic
defect detect_cast =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.FieldDeclaration.cast(n, &fd)
and fd.nodeText(&txt)
raise "Cast to FieldDeclaration: {txt}"
on fdIn this C++ code the defect locates the member
struct S { int x = 42; }; |
isa(Cpp.Node.Node node)
| Returns true if the given generic Node is a
field_declaration. Useful for boolean checks or
negation. | This PQL defect checks whether a node is a
defect detect_isa =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.FieldDeclaration.isa(n)
raise "Node is a FieldDeclaration"
on nIn this C++ code the defect confirms the member
struct S { int x; }; |
declarator(FieldDeclaration self, Cpp.Node.Node &child)
| Matches the declarator child of the field declaration and returns it as
child. | This PQL defect checks for the declarator part of a
defect detect_declarator =
when
Cpp.FieldDeclaration.is(&fd)
and fd.declarator(&decl)
and decl.nodeText(&txt)
raise "Declarator: {txt}"
on declIn this C++ code the defect extracts the
declarator
struct S { int x = 42; }; |
defaultValue(FieldDeclaration self, Cpp.Node.Node &child)
| Matches the default initializer expression or clause of the field and returns
it as child. | This PQL defect checks for a field's default initializer expression. defect detect_default =
when
Cpp.FieldDeclaration.is(&fd)
and fd.defaultValue(&val)
and val.nodeText(&txt)
raise "Default value: {txt}"
on valIn this C++ code the defect finds the initializer
struct S { int x = 42; }; |
type_(FieldDeclaration self, Cpp.Node.Node &child)
| Matches the type specifier or declarator type node of the field and eturns it
as child. | This PQL defect checks for the type portion of a
defect detect_type =
when
Cpp.FieldDeclaration.is(&fd)
and fd.type_(&t)
and t.nodeText(&txt)
raise "Field type: {txt}"
on tIn this C++ code the defect finds the type
struct S { int x; }; |
attributeSpecifier(FieldDeclaration self, Cpp.Node.Node
&child)
| Matches attribute specifiers like [[nodiscard]] attached to
the field and returns it as child.. | This PQL defect checks for C++ attribute specifiers on fields. defect detect_attr_spec =
when
Cpp.FieldDeclaration.is(&fd)
and fd.attributeSpecifier(&a)
and a.nodeText(&txt)
raise "Attribute specifier: {txt}"
on aIn this C++ code the defect detects
struct S { [[nodiscard]] int y; }; |
virtual_(FieldDeclaration self, Cpp.Node.Node &child)
| Matches the virtual keyword if present on the field and
returns it as child. | This PQL defect checks for the presence of the defect detect_virtual =
when
Cpp.FieldDeclaration.is(&fd)
and fd.virtual_(&v)
and v.nodeText(&txt)
raise "Virtual specifier: {txt}"
on vIn this C++ code the defect finds
struct S { virtual int z; }; |
bitfieldClause(FieldDeclaration self, Cpp.Node.Node &child)
| Matches the bitfield width clause (e.g. : 3) of the field
and returns it as child. | This PQL defect checks for bitfield declarations on fields. defect detect_bitfield =
when
Cpp.FieldDeclaration.is(&fd)
and fd.bitfieldClause(&bf)
and bf.nodeText(&txt)
raise "Bitfield clause: {txt}"
on bfIn this C++ code the defect identifies the
struct S { int w : 3; }; |
msDeclspecModifier(FieldDeclaration self, Cpp.Node.Node
&child)
| Matches Microsoft __declspec(...) modifiers applied to the
field and returns it as child. | This PQL defect checks for MSVC defect detect_ms_declspec =
when
Cpp.FieldDeclaration.is(&fd)
and fd.msDeclspecModifier(&m)
and m.nodeText(&txt)
raise "MS __declspec modifier: {txt}"
on mIn this C++ code the defect finds
struct S { __declspec(align(16)) int a; }; |
storageClassSpecifier(FieldDeclaration self, Cpp.Node.Node
&child)
| Matches storage-class specifiers such as static and returns
it as child. | This PQL defect checks for storage-class specifiers on fields. defect detect_storage_class =
when
Cpp.FieldDeclaration.is(&fd)
and fd.storageClassSpecifier(&sc)
and sc.nodeText(&txt)
raise "Storage class: {txt}"
on scIn this C++ code the defect finds
struct S { static const int b = 1; }; |
typeQualifier(FieldDeclaration self, Cpp.Node.Node &child)
| Matches type qualifiers like const or
volatile applied to the field and returns it as
child. | This PQL defect checks for type qualifiers on fields. defect detect_type_qual =
when
Cpp.FieldDeclaration.is(&fd)
and fd.typeQualifier(&q)
and q.nodeText(&txt)
raise "Type qualifier: {txt}"
on qIn this C++ code the defect finds
struct S { const int c; }; |
attributeDeclaration(FieldDeclaration self, Cpp.Node.Node
&child)
| Matches attribute declarations such as [[deprecated]]
attached to the field and returns them as child. | This PQL defect checks for attribute declarations on fields. defect detect_attr_decl =
when
Cpp.FieldDeclaration.is(&fd)
and fd.attributeDeclaration(&ad)
and ad.nodeText(&txt)
raise "Attribute declaration: {txt}"
on adIn this C++ code the defect detects
struct S { [[deprecated]] int d; }; |
getEnclosingFieldDeclaration(Cpp.Node.Node child, required FieldDeclaration
&parent)
| Finds the nearest ancestor field_declaration for a given
Node and returns that parent. | This PQL defect checks for the field declaration that encloses a generic syntax node. defect detect_enclosing_field =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.FieldDeclaration.getEnclosingFieldDeclaration(node, &fd)
and fd.nodeText(&txt)
raise "Enclosing field: {txt}"
on fdIn this C++ code the defect locates the field
struct S { int x = 42; }; |
isEnclosedInFieldDeclaration(Cpp.Node.Node child)
| Returns true when the given Node has a
field_declaration ancestor. | This PQL defect checks whether a node is nested inside any
defect detect_enclosed_in_field =
when
Cpp.Node.is(&node,&,&,&)
and Cpp.FieldDeclaration.isEnclosedInFieldDeclaration(node)
raise "Identifier is inside a field declaration"
on nodeIn this C++ code the defect finds all syntax
nodes that are enclosed by the
struct S { int x = 42; }; |
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)