[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

Alan Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 17:33:48 PDT 2022


ayzhao added a comment.

Status update:

While investigating @cor3ntin's comment about refactoring `VisitInitListExpr` and `VisitCXXParenListInitExpr` as they share common code, I discovered that flexible array members would cause this patch to explode. Specifically, the following code:

  struct S {
      int b;
      int a[];
  };
  
  S s2(1, {1, 2});

was causing this assertion <https://github.com/llvm/llvm-project/blob/3f18f7c0072b642f5fe88d2fb7bb8ccf69a6c6f5/clang/lib/CodeGen/CGExprAgg.cpp#L480> to fail.

I took a look at GCC, and it turns out that GCC doesn't allow flexible array members at all in paren list initialization of aggregates, even in contexts where the corresponding designated initializer expression succeeds: https://godbolt.org/z/E73433erb

For now, I updated this implementation to follow GCC's behavior and disallow flexible array members, as IIRC in C++ they are a GCC extension and we should therefore follow GCC behavior. However, I am open to other thoughts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531



More information about the cfe-commits mailing list