\aftergroup was unsupported, so class-style deferred setup leaked. Expansion
now keeps a parallel stack of pending token lists: '{' and \begingroup push an
empty list, '}' and \endgroup pop it and append its tokens after the group (the
closing brace is emitted first, then the pending tokens with the command-end
marker so a control word cannot merge with the following text).
\aftergroup<token> queues one token and \aftergroup{...} queues the group body.
A test defines a group-local \a while queueing \aftergroup\a, then checks that
the queued \a runs after the group restores A, giving "AA and !X" with no
warnings.