Repository navigation
Bind an NSDMI's implicit this to the constructed object in a constructor init [GH #324] - #540
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI success. |
| // are used by a constructor (and not folded into a constant). | ||
| template <class T> struct Der : T { Der() {} }; | ||
|
|
||
| // Nested aggregates of different classes (PR c++/100252). |
There was a problem hiding this comment.
What's that c++/100252 referring to? A GCC bug number? Why is that relevant?
There was a problem hiding this comment.
Yes, it's a GCC bug; its fix added the nsdmi-aggr14 to nsdmi-aggr19 tests, and this case has the same shape
https://gcc.gnu.org/pipermail/gcc-patches/2022-May/594855.html
|
I don't think the "Tests" section in the PR description is particularly useful. If the test needs to be clarified, it should be in the test itself, not in the PR description. And I don't really want to know what tests your AI agent ran before submitting the PR (all tests need to pass anyway). Same for things like "The commit message passes edg-check-commit-messages." |
6e2811d to
69298c9
Compare
|
Thanks, I removed the Tests section and the notes about which checks were run. The description now covers the problem, the standard references, the cause and the change. |
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI success. |
daveedvdv-nvidia
left a comment
There was a problem hiding this comment.
Looks good overall.
Only wording changes needed as far as I'm concerned.
| initialized by "Y{2, k}". The aggregates for which an explicitly specified | ||
| element is being lowered are therefore skipped. | ||
| element is being lowered are therefore skipped. When no other aggregate | ||
| matches, the "this" of a constructor init comes next, as in: |
There was a problem hiding this comment.
s/the "this" of/the "this" parameter of/
…tor init [GH edgcpp#324] When a default member initializer that aggregate-initializes another object of the same class was used by a constructor, lower_param_ref searched every aggregate on aggregate_this_stack, including the ones skipped because one of their explicit elements was being lowered, before it tried the "this" parameter of the constructor init: struct Y { unsigned k = 7; unsigned n = Y{2, k}.n; }; struct D : Y { D() {} }; // D().n was 2, not 7. The "this" parameter of the constructor init is now used before the skipped aggregates are searched.
69298c9 to
7438f6b
Compare
|
AcknowlEDG review results updated for
|
|
AcknowlEDG review results updated for
CI success. |
Follow-up to #408 for discussion #324. #408 fixed the implicit
thisof a default member initializer that aggregate-initializes another object of the same class, but only when the default member initializer is used by an aggregate initialization. When it is used by a constructor,thisstill bound to the nested temporary:khere is(*this).k([class.mfct.non-static]/3, [expr.prim.id.general] in C++23).thisnames the object whose non-static data member's initializer is being evaluated ([expr.prim.this]/1), and Y's constructor initializesnfrom its default member initializer ([class.base.init]/9, [class.default.ctor]/4). Sonis 7.This affects every case where Y's constructor runs:
D(),D() : Y() {}, a memberY y;of a class with a user-provided constructor, an array member,new Y[2], andY y;when an initializer is not a constant (otherwise the front end foldsY y;to{7U, 7U}). Aggregate initialization (Y{},D() : Y{} {}) was already correct.Cause
lower_param_ref(lower_il.c) replaced theenk_param_refforthiswith, in order:aggregate_this_stack(Bind an NSDMI's implicit this to the right aggregate [GH #324] #408 skips an aggregate while one of its explicit elements is lowered),ctor_init_this, thethisparameter of the constructor init being lowered.In Y's constructor, the temporary for
Y{2, k}is skipped while its explicit elementkis lowered, so step 1 finds nothing and step 2 takes that temporary. The lowered constructor read__T.n = __T.k;instead of__T.n = this->k;.Change
lower_param_refnow tries the constructor'sthis(when its type matches) after the candidate search and before the search that includes the skipped aggregates. While a constructor init is lowered, every entry on the stack was pushed by it (constructor inits don't nest), and a skipped entry is never what an explicit element'sthisrefers to, so the constructor'sthisis right whenever no candidate matches. The search that includes the skipped aggregates stays as the last resort outside constructor inits.New test:
regressions/gh-324-ctor-init.Summary by CodeRabbit
this, including when initializing another object of the same class. References in nested initialization now resolve to the object being constructed.thisparameter type does not match a referenced parameter.