[PATCH] D17407: [Sema] PR25755 Fix crash when initializing out-of-order struct references

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 7 18:23:44 PDT 2016


rsmith added a comment.

In http://reviews.llvm.org/D17407#385208, @hintonda wrote:

> I'm probably missing something, but isn't InitListChecker::CheckStructUnionTypes() called recursively, if indirectly?  In which case we'd want to start from the Field iterator we were given, not the look at all the fields.


No: if `CheckDesignatedInitializer` finds a top-level designator (denoting a field in the same struct for which it was called, rather than a subobject of that field), it just returns. `CheckStructUnionTypes` should never recursively re-enter the same subobject.

However, you do make a good point: we *can* enter `CheckStructUnionTypes` multiple times for the same subobject, in a case like

  struct Q { Q(int); }
  struct A { Q x, y; };
  struct B { A a; int k; };
  B b = { .a.y = 0, 0, .a.x = 0 };

... and we should not `CheckEmptyInitializable` in that case, nor warn that an initializer for `a.x` is missing. (But we should do so if the final initializer for `a.x` is not present.)

It looks like we need to do all this checking as a separate pass after checking the initialization, even in `VerifyOnly` mode.


http://reviews.llvm.org/D17407





More information about the cfe-commits mailing list