================
@@ -738,7 +738,7 @@ bool ConstStructBuilder::Build(const InitListExpr *ILE, 
bool AllowOverwrite) {
     // Zero-sized fields are not emitted, but their initializers may still
     // prevent emission of this struct as a constant.
     if (isEmptyFieldForLayout(CGM.getContext(), Field)) {
-      if (Init->HasSideEffects(CGM.getContext()))
+      if (Init && Init->HasSideEffects(CGM.getContext()))
----------------
AaronBallman wrote:

> Should we allow this for SemaRef.getLangOpts().C23 too perhaps?

Empty initialization ends up in C's "default initialization" rules, which does:

> If an object that has automatic storage duration is not initialized 
> explicitly, its representation is indeterminate. If an object that has static 
> or thread storage duration is not initialized explicitly, or any object is 
> initialized with an empty initializer, then it is subject to default 
> initialization, which initializes an object as follows:
— if it has pointer type, it is initialized to a null pointer;
— if it has decimal floating type, it is initialized to positive zero, and the 
quantum exponent is
implementation-defined;
— if it has arithmetic type, and it does not have decimal floating type, it is 
initialized to (positive
or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to 
these rules, and any padding is initialized to zero bits;
— if it is a union, the first named member is initialized (recursively) 
according to these rules, and any padding is initialized to zero bits.

So yeah, I think we should do this in C23 mode.

https://github.com/llvm/llvm-project/pull/109271
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to