================
@@ -4188,6 +4188,109 @@ void Parser::ParseTrailingRequiresClause(Declarator &D) 
{
   }
 }
 
+/// Parse a sequence of C++26 contract specifiers (P2900R14).
+///
+/// Called from ParseFunctionDeclarator after the trailing return type,
+/// while still inside the function prototype scope (parameters are visible).
+///
+///   function-contract-specifier-seq:
+///     function-contract-specifier
+///     function-contract-specifier-seq function-contract-specifier
+///
+///   function-contract-specifier:
+///     'pre' '(' conditional-expression ')'
+///     'post' '(' result-name-introducer[opt] conditional-expression ')'
+///
+///   result-name-introducer:
+///     identifier ':'
+///
+/// 'pre' and 'post' are context-sensitive keywords (identifiers that are
+/// only special in this position). Parsed specifiers are stored in the
+/// Declarator and later converted to ContractAnnotation nodes on
+/// FunctionDecl by Sema::ActOnFunctionContractSpecifiers.
+///
+/// \param TrailingReturnType The trailing return type (if any), needed to
+///        determine the type of the result variable in post(name: expr).
+///        For non-trailing return types (e.g. `int f()`), pass ParsedType().
+void Parser::ParseContractSpecifiers(Declarator &D,
+                                     ParsedType TrailingReturnType) {
+  if (!getLangOpts().Contracts)
+    return;
+
+  // Lazily initialize context-sensitive keyword identifiers.
+  if (!Ident_pre) {
----------------
yronglin wrote:

I think we should init the `pre`, `post` identifier in 
`IdentifierTable::AddKeyword`, like the module contextual keyword:
https://github.com/llvm/llvm-project/blob/3fd56af03613059ba3edd30d7c60aaf50956e951/clang/lib/Basic/IdentifierTable.cpp#L305-L308

https://github.com/llvm/llvm-project/pull/205739
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to