Commit 18168a9
[clang][reflection] Complete reflected specializations with implicit-instantiation semantics
SemaMetaActions::EnsureInstantiated -- the single completion funnel for every
type-completing metafunction (members_of, bases_of, size_of, is_complete_type,
...) -- completed class template specializations with
TSK_ExplicitInstantiationDefinition plus
InstantiateClassTemplateSpecializationMembers, eagerly instantiating every
member DEFINITION. A specialization whose never-odr-used member bodies are
ill-formed -- the "specialized storage base" idiom, valid C++ as long as those
members are never odr-used; tl::expected<void, E> is the field shape (nine
hard errors out of its implementation details) -- was wrong-rejected, but ONLY
when reflection reached the type before ordinary use did: a preceding
`Exp<void> ok_instance;` made the identical members_of loop compile clean
(order-dependent enumeration). The eager kind also marked the specialization
as if the user had written an explicit instantiation definition, forcing
weak-ODR emission of every member in the TU and colliding with genuine
explicit instantiations.
Fix: mirror Sema::RequireCompleteTypeImpl -- TSK_ImplicitInstantiation with
the specialization's strict-pack-match flag, member definitions left to lazy
odr-use-driven instantiation, plus the member-class-of-a-template branch
(InstantiateClass on getInstantiatedFromMemberClass) that the eager member
sweep used to cover as a side effect. Body-needing consumers (extract,
reflect_invoke, deduced-return substitute) re-enter EnsureInstantiated with
the specific FunctionDecl/VarDecl, whose branches are untouched.
Test: members-of-lazily-ill-formed-bodies.pass.cpp -- five distinct templates
so each metafunction is the FIRST instantiation trigger, an
order-independence control, and a runtime check that odr-used bodies still
instantiate lazily.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 837da39 commit 18168a9
2 files changed
Lines changed: 126 additions & 5 deletions
File tree
- clang/lib/Sema
- libcxx/test/std/experimental/reflection
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
290 | 299 | | |
291 | | - | |
292 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
293 | 320 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | 321 | | |
298 | 322 | | |
299 | 323 | | |
| |||
Lines changed: 97 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
0 commit comments