[clang] [C++26] [Contracts] Initial parser support (PR #221139)
Yihan Wang via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 14 23:23:30 PDT 2026
================
@@ -2052,6 +2052,19 @@ class Declarator {
Expr *PackIndexingExpr;
+public:
+ /// A function contract specifier whose predicate must be parsed after its
+ /// enclosing class is complete.
+ struct LateParsedContractSpecifier {
+ bool IsPost;
+ IdentifierInfo *ResultName = nullptr;
+ SourceLocation ResultNameLoc;
+ std::unique_ptr<CachedTokens> PredicateTokens;
+ };
+
+private:
+ SmallVector<LateParsedContractSpecifier, 2> LateParsedContractSpecifiers;
----------------
yronglin wrote:
IIUC, we should cleanup this when clearing Declarator states, the following code should be accepted, but clang rejected it with: `error: virtual specifier 'override' must appear before contract specifiers`:
```cpp
struct Base {
virtual void g();
};
struct Derived : Base {
void f() pre(true),
g() __attribute__((unused)) override;
};
```
https://github.com/llvm/llvm-project/pull/221139
More information about the cfe-commits
mailing list