[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 2 08:45:26 PDT 2023
erichkeane added inline comments.
================
Comment at: clang/lib/Sema/SemaType.cpp:8824
+ if (auto *Cast = dyn_cast<CXXStaticCastExpr>(E)) {
+ if (auto *SubInit = dyn_cast<CXXParenListInitExpr>(Cast->getSubExpr())) {
+ const Type *InnerType = SubInit->getType().getTypePtr();
----------------
Fznamznon wrote:
> erichkeane wrote:
> > I am not really sure this is the right way about this. You're supposed to be testing `T`, but this looks like it is checking the type of `E`, isn't it? I think you just need to check `Cast->getType()`.
> For the case I'm trying to fix, `T` is array of unknown bound, it is already checked before calling `completeExprArrayBound`. Right now when you write something like
> ```
> int (&&arr1)[1] = static_cast<int[]>(42);
> ```
> Clang actually is able to realize that parenthesized initialization is made, so it actually generates `CXXParenListInitExpr` that has type int[1]. Here I'm just paranoidally double-checking that is the case before switching the type. Maybe I don't need this double-check at all then?
>
That makes me wonder if this is the correct place for this? Should when we generate this type when we do the `CXXParenListInitExpr` fixup?
Either way, I think making this depend on that behavior (which would possibly be fragile), we should just do it based on the type passed ot the `static_cast`.
Another question: is this something that needs to be done for other cast types? Does similar behavior exist for the other casts? Should it also happen with 'clobber' casts (C-style) that are effectively static?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152003/new/
https://reviews.llvm.org/D152003
More information about the cfe-commits
mailing list