[PATCH] D107275: [Sema] a[x] has type T when a has type T* or T[], even when T is dependent

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 30 12:21:08 PST 2021


sammccall added a comment.

In D107275#3182906 <https://reviews.llvm.org/D107275#3182906>, @kadircet wrote:

> I am more worried about creating "incorrect" nodes in some cases. I think it isn't valid in C/C++ for both LHS && RHS to be pointers/arrays in a subscript expression, but I've got no idea about when it's diagnosed in clang and what is put into the AST.
>
> ... we'll have a bunch of expressions with erroneous `ResultType` info which might trip over some things.

Yeah, I think this is a problem. To put it another way:

- if `X is Foo*` and y is dependent, `x[y]` has type `Foo` *or* it is invalid
- if we claim it has type `Foo` then either template-instantiation must check it's valid, or we may accept invalid code
- accepting invalid code can turn into miscompiles via SFINAE

Probably rebuilding during template instantiation does verify enough but I'm not 100% sure.

In the motivating case, the subscript is a known integer type and the LHS is an array or pointer. In this case we don't have the above concern, and we also don't have my #1 above. So I'll restrict the code to cover that case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107275



More information about the cfe-commits mailing list