I'm updating a huge legacy system, and am currently stumped by the following function:
template <class EL>
EL& FastInsertVector<EL>::operator[](size_type index)
{
return (EL&) FastInsertVectorBase::operator [][](index);
}
MS VC++ 2022 compiles it happily, whereas C++ Builder 11.1.5 rejects it saying:
expected expression
If I remove the second set of []
, both compilers are happy. Unfortunately, this is shared code that both compilers must be able to handle.
This codebase is huge, and has no tests, and I'm having difficulty actually understanding what this syntax even means.
Is this valid C++ syntax? Can anyone explain what it's trying to express?
operator[][]
in C++, and there never was. It's necessary to figure out what that abomination was actually accomplishing, and then reimplement it in standard C++. Perhaps hunt down the definition ofFastInsertVectorBase
, and look at what it's defining.[]
afaik allows for this syntax. assuming the intention here is to invoke the versionoperator[]
implemented in the ancestorFastInsertVectorBase
,FastInsertVectorBase::operator[](index)
is indeed the correct syntax according to the standard... Btw: have you actually used this function in MSVC. MSVC may be a bit sloppy with syntax checks for non-specialized templates.operator[]
and cast whatever it returns toEL
. I.e. it wants to doreturn (EL&) FastInsertVectorBase::operator[](index);
. The double[][]
is pretty certainly not valid syntax. However, MSVC does not complain about it as long as the function does not get instantiated (i.e. called), compare godbolt. So my guess is that the shownFastInsertVector<EL>::operator[]
is actually unused in the code and could be removed entirely.