[clang] [Clang] Sequence the object argument of an overloaded operator[] or operator() first (PR #215479)

Xavier Roche via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 2 00:49:56 PDT 2026


xroche wrote:

> Please check what MSVC actually does here. Some brief testing seems to show that it does straight left-to-right for array indexing, instead of the mixed ordering you've implemented.

You're correct right for the simple case.

[Demo with MSVC 14.51](https://godbolt.org/clientstate/eNqVVFFvgjAQ_itNHxaNJIbNEYe_YC_zYcte1DRdqa4MW9IWNCHut6-0gCA4Ywihd_fdx_W7awuoqFJMcAXDVQFZBEPfgwnmuwzvKAwhmUygB5XIJClNpWVGNHjlET2CYs0BYFyDHCcZXZSWDYzGrTUx3HXCgwv8nlEn87rYHv9QtGVSaRtoORU1HJH1lj-zPtY1Y2uueVXeh2Q5w8nyK6bGGiiztERKJdZCrjYj_c3URZKiydazOOY-8fiuTFc_qxdxvdku1havnavZUWUjsx6NQQEk1ZnkF9hVLYPXKLBZgFOXgSRYqVscleZeV2xH1ij6Jri-JeolphqDnttNRI-xHo4rNEPC9zju6dqV5GuN68GtXLzxNu07uwY72M74t4ktnuE-9pn-a6U5xUTsU5ZQeT7rMCdpinL_BT376PPdn6MAHYOZwYpUu1sBTpWOQnMNPD6lkuaMHsB06YPpwZ_NgwCeNub5A6plgOs) : `object, i, j` with a trivial object and `int` indices.

In the other three cases, with a nontrivial by-value object or indices, MSVC emits `j, i, object`. With `/w14866`, it reports [C4866](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c4866?view=msvc-170) for each.

AFAIU [C++23](https://eel.is/c++draft/expr.sub) requires the object first but leaves index order open. I've changed Clang's overloaded `operator[]` notation to use `object, i, j`. `operator()` still uses ABI order after the object.



https://github.com/llvm/llvm-project/pull/215479


More information about the cfe-commits mailing list