aboutsummaryrefslogtreecommitdiff
path: root/clang/include/clang/ASTMatchers/ASTMatchers.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/include/clang/ASTMatchers/ASTMatchers.h')
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 55cce324b436..86bd44091b59 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3725,10 +3725,9 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiver, internal::Matcher<Expr>,
/// \endcode
AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) {
Selector Sel = Node.getSelector();
- return BaseName.compare(Sel.getAsString()) == 0;
+ return BaseName == Sel.getAsString();
}
-
/// Matches when at least one of the supplied string equals to the
/// Selector.getAsString()
///
@@ -5171,6 +5170,25 @@ AST_POLYMORPHIC_MATCHER(isNoThrow,
return FnTy->isNothrow();
}
+/// Matches consteval function declarations and if consteval/if ! consteval
+/// statements.
+///
+/// Given:
+/// \code
+/// consteval int a();
+/// void b() { if consteval {} }
+/// void c() { if ! consteval {} }
+/// void d() { if ! consteval {} else {} }
+/// \endcode
+/// functionDecl(isConsteval())
+/// matches the declaration of "int a()".
+/// ifStmt(isConsteval())
+/// matches the if statement in "void b()", "void c()", "void d()".
+AST_POLYMORPHIC_MATCHER(isConsteval,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, IfStmt)) {
+ return Node.isConsteval();
+}
+
/// Matches constexpr variable and function declarations,
/// and if constexpr.
///
@@ -5193,6 +5211,23 @@ AST_POLYMORPHIC_MATCHER(isConstexpr,
return Node.isConstexpr();
}
+/// Matches constinit variable declarations.
+///
+/// Given:
+/// \code
+/// constinit int foo = 42;
+/// constinit const char* bar = "bar";
+/// int baz = 42;
+/// [[clang::require_constant_initialization]] int xyz = 42;
+/// \endcode
+/// varDecl(isConstinit())
+/// matches the declaration of `foo` and `bar`, but not `baz` and `xyz`.
+AST_MATCHER(VarDecl, isConstinit) {
+ if (const auto *CIA = Node.getAttr<ConstInitAttr>())
+ return CIA->isConstinit();
+ return false;
+}
+
/// Matches selection statements with initializer.
///
/// Given: