[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 23:00:01 PDT 2023


cor3ntin added a comment.

Thanks Shafik.

I have some concern about the diagnostics being wonky because,  if the init and field don't match,  it's hard to be sure we won't run into simar issues (although i agree this fixes the crash.)

Also, I'm not saying you should do this but... maybe this thing could be improved by a sort of `field_iterator` that skips over unnamed bitfield.



================
Comment at: clang/lib/Sema/SemaInit.cpp:2836-2837
           continue;
         if (*NextField != RD->field_end() &&
             declaresSameEntity(*FI, **NextField))
           break;
----------------
I think this is probably where it fails produce something sensible to diagnostics.
in the `*NextField == RD->field_end()` case we just go straight to the end.

In that case, we probably want to break when the previous element is the one under test, that way you might get to `b`.



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154675/new/

https://reviews.llvm.org/D154675



More information about the cfe-commits mailing list