[clang] [C++26] [Contracts] Initial parser support (PR #221139)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 02:36:06 PDT 2026
================
@@ -4244,6 +4222,142 @@ void Parser::ParseTrailingRequiresClause(Declarator &D) {
}
}
+std::optional<Parser::ContractSpecifierKind>
+Parser::getContractSpecifierKind() {
+ if (!getLangOpts().CPlusPlus || Tok.isNot(tok::identifier))
+ return std::nullopt;
+
+ if (!Ident_pre) {
+ Ident_pre = &PP.getIdentifierTable().get("pre");
+ Ident_post = &PP.getIdentifierTable().get("post");
+ }
+
+ const IdentifierInfo *II = Tok.getIdentifierInfo();
+ if (II == Ident_pre)
+ return ContractSpecifierKind::Pre;
+ if (II == Ident_post)
+ return ContractSpecifierKind::Post;
+ return std::nullopt;
+}
+
+void Parser::ParseContractSpecifiers(Declarator &D) {
+ assert(getContractSpecifierKind() && "expected a contract specifier");
+
+ if (!getLangOpts().CPlusPlus26)
+ Diag(Tok, diag::err_contracts_require_cxx26);
----------------
ChuanqiXu9 wrote:
Yeah, agreed.
https://github.com/llvm/llvm-project/pull/221139
More information about the cfe-commits
mailing list