[clang] [Clang] Instantiate constexpr function when they are needed. (PR #173537)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 06:40:53 PDT 2026


================
@@ -786,6 +797,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
   /// Keeps track of the deallocated DeclListNodes for future reuse.
   DeclListNode *ListNodeFreeList = nullptr;
 
+  std::unique_ptr<SemaProxy> SemaProxyPtr;
----------------
AaronBallman wrote:

I'm not comfortable with the idea that any AST evaluation whatsoever will now always carry the potential to mutate the AST and it's up to the caller to determine whether that's possible based on contextual clues. I don't think that's the status quo -- if I call `Expr::HasSideEffects()` today, I don't expect that to mutate my AST out from under me. If I call `Expr::tryEvaluateString()` I might expect that to fail instead of mutating the AST out from under me. I expect this to only impact interfaces like `EvaluateAsConstantExpr()` where the evaluation of the constant expression is explicitly requested. I think using function parameters to be explicit with that request makes a lot of sense, too, because I expect there are consumers of these APIs that *never want to mutate the AST* an encoding that in the API itself gives a much stronger guarantee than a hidden pointer.


https://github.com/llvm/llvm-project/pull/173537


More information about the cfe-commits mailing list