Defer expansion statement body instantiation#261
Open
Perdixky wants to merge 2 commits intobloomberg:p2996from
Open
Defer expansion statement body instantiation#261Perdixky wants to merge 2 commits intobloomberg:p2996from
Perdixky wants to merge 2 commits intobloomberg:p2996from
Conversation
added 2 commits
February 5, 2026 18:58
Compute expansion size and instantiate after expansion to avoid premature body instantiation and spurious diagnostics. Reproducer: https://godbolt.org/z/dxqPxe6ed
- Change ExpansionStmtDecl to store Stmt* instead of CXXExpansionStmt* to support expanded CompoundStmt results from non-dependent expansions - Update ExpansionStmtDecl::Create, constructor, getStmt, and setStmt signatures to use Stmt* - Modify FinishCXXExpansionStmt(Heading, Body) to delegate to the new FinishCXXExpansionStmt(Stmt*, UnsignedOrNone) after setting the body - Remove redundant expansion logic from the old overload - Update callers in ParseStmt.cpp, SemaTemplateInstantiateDecl.cpp, and ASTReaderDecl.cpp to remove unnecessary casts
There was a problem hiding this comment.
Pull request overview
This PR defers expansion statement body instantiation to avoid premature instantiation and spurious diagnostics when working with nested template expansions over annotations.
Changes:
- Refactored
ExpansionStmtDeclto store a genericStmt*instead ofCXXExpansionStmt*to support deferred instantiation - Added a new
FinishCXXExpansionStmtoverload that takesUnsignedOrNone Sizeto enable deferred body instantiation - Updated parsing, serialization, and template instantiation code to work with the more general
Stmt*type - Added test coverage for nested template for loops over annotations and error cases
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| libcxx/test/std/experimental/reflection/p3394-annotations.pass.cpp | Added test for nested template for over annotations, plus formatting improvements |
| clang/test/SemaCXX/cxx2c-expansion-stmts.cpp | Added tests for non-constant expansion size and label diagnostics |
| clang/lib/Sema/SemaExpand.cpp | Refactored to support deferred expansion with new FinishCXXExpansionStmt overload |
| clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | Updated to work with Stmt* type, formatting improvements |
| clang/lib/Serialization/ASTReaderDecl.cpp | Updated deserialization to use readStmt(), formatting improvements |
| clang/lib/Parse/ParseStmt.cpp | Updated parser to work with Stmt* type, formatting improvements |
| clang/lib/AST/DeclTemplate.cpp | Updated ExpansionStmtDecl implementation, formatting improvements |
| clang/lib/Sema/SemaReflect.cpp | Removed redundant comment |
| clang/include/clang/Sema/Sema.h | Added new FinishCXXExpansionStmt signature |
| clang/include/clang/AST/DeclTemplate.h | Changed ExpansionStmtDecl to use Stmt* instead of CXXExpansionStmt* |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Compute expansion size and instantiate after expansion to avoid premature body instantiation and spurious diagnostics. Reproducer: https://godbolt.org/z/dxqPxe6ed