Cpp.RequiresClause Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the requires_clause nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.RequiresClause represents the node requires_clause in the syntax tree of your code.
template<typename T>
requires std::integral<T>
void foo(T t) {}The requires std::integral<T> part of the example corresponds to the requires_clause node handled by Cpp.RequiresClause.
Predicates
| Type | Raisable | Printable |
|---|---|---|
RequiresClause
| 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 RequiresClause &rc)
| Checks whether a syntax node is a requires_clause and binds
it to rc. Use this to directly select requires
clauses. | This PQL defect checks for defect defectIs =
when
Cpp.RequiresClause.is(&rc)
and rc.nodeText(&txt)
raise "RequiresClause.is matched: \"{txt}\""
on rcIn this C++ code the defect finds the
template<typename T>
requires (sizeof(T) <= 8 && sizeof(T) >= 1)
void foo(T) {}
int main() {
foo(42); // OK - int satisfies the requirements
foo('a'); // OK - char satisfies the requirements
return 0;
}
|
cast(Cpp.Node.Node node, required RequiresClause &cast)
| Treats an arbitrary Node as a
requires_clause if its runtime kind matches and binds it to
cast. Use this when you have a generic node and need
requires_clause-specific predicates. | This PQL defect checks for defect defectCast =
when
Cpp.TemplateDeclaration.is(&td)
and td.getADescendant(&node)
and Cpp.RequiresClause.cast(node, &rc)
and rc.nodeText(&txt)
raise "RequiresClause.cast matched: \"{txt}\""
on rcIn this C++ code the defect finds a
template<typename T>
requires (sizeof(T) <= 8 && sizeof(T) >= 1)
void foo(T) {}
int main() {
foo(42); // OK - int satisfies the requirements
foo('a'); // OK - char satisfies the requirements
return 0;
}
|
isa(Cpp.Node.Node node)
| Checks whether a generic Node is a
requires_clause without binding it. Use this for boolean tests
or negations. | This PQL defect checks whether a generic defect defectIsa =
when
Cpp.TemplateDeclaration.is(&td)
and td.getADescendant(&node)
and Cpp.RequiresClause.isa(node)
raise "Node is a RequiresClause"
on tdIn this C++ code the defect verifies that a
template declaration contains a
template<typename T>
requires (sizeof(T) <= 8 && sizeof(T) >= 1)
void foo(T) {}
int main() {
foo(42); // OK - int satisfies the requirements
foo('a'); // OK - char satisfies the requirements
return 0;
}
|
constraint(RequiresClause self, Cpp.Node.Node &child)
| Selects the constraint expression node inside a
requires_clause and binds it to child. Use
this to inspect the concept or expression following
requires. | This PQL defect checks for the constraint expression inside a
defect defectConstraint =
when
Cpp.RequiresClause.is(&rc)
and rc.constraint(&constraint)
and constraint.nodeText(&txt)
raise "RequiresClause.constraint matched: \"{txt}\""
on constraintIn this C++ code the defect extracts the
#include <concepts>
template<typename T>
requires std::integral<T>
void foo(T) {}
int main() {} |
getEnclosingRequiresClause(Cpp.Node.Node child, required RequiresClause
&parent)
| Finds the nearest enclosing requires_clause that contains
child and binds it to parent. Use this to
map inner nodes back to their requires context. | This PQL defect checks for the nearest enclosing
defect defectEnclosing =
when
Cpp.TypeIdentifier.is(&id)
and id.toNode(&node)
and Cpp.RequiresClause.getEnclosingRequiresClause(node, &rc)
raise "Identifier is inside requires clause"
on idIn this C++ code the defect finds type identifiers
that appear inside a
#include <concepts>
template<typename T>
requires std::integral<T>
void foo(T) {}
int main() {} |
isEnclosedInRequiresClause(Cpp.Node.Node child)
| Checks whether child has any
requires_clause ancestor. Use this to filter nodes that appear
within requires clauses. | This PQL defect checks whether a given type identifier is anywhere inside
a
defect defectIsEnclosed =
when
Cpp.TypeIdentifier.is(&id)
and id.toNode(&node)
and Cpp.RequiresClause.isEnclosedInRequiresClause(node)
raise "Identifier enclosed in requires clause"
on idIn this C++ code the defect flags type identifiers
that belong to the
#include <concepts>
template<typename T>
requires std::integral<T>
void foo(T) {}
int main() {} |
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)