[PATCH] D124038: [clang] Prevent folding of non-const compound expr
Eli Friedman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 9 13:38:19 PDT 2022
efriedma added inline comments.
================
Comment at: clang/lib/AST/ExprConstant.cpp:4267
+ bool IsConstant = CLETy.isConstant(Info.Ctx);
+ if (!IsConstant && CLETy->isArrayType()) {
+ Info.FFDiag(Conv);
----------------
serge-sans-paille wrote:
> efriedma wrote:
> > Is the "isArrayType()" check here necessary?
> Yeah, otherwise we have an issue with
>
> ```
> typedef __attribute__(( ext_vector_type(4) )) float float4;
> float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
> ```
>
> error: cannot compile this static initializer yet
Hmm, I see... in C++, the compound literal rules are weird. C compound literals are lvalues, but C++ ones are not. So normally, we don't allow taking the address of a compound literal or any of its members. But if it's an array, somehow different rules (what rules?) apply.
If you can add a comment explaining what's going on here, maybe it's okay?
I'm tempted to say we should reject the testcase, though. For example, in the following, it doesn't really make sense to reject the first variable, but accept the second.
```
typedef int arr[2];
constexpr int *x = arr{1};
constexpr int *y = (arr){1};
```
------
Can you add a testcase involving an array of structs with a "mutable" member?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124038/new/
https://reviews.llvm.org/D124038
More information about the cfe-commits
mailing list