c++compiler-warningsc++23subscript-operatorgcc12

warning: top-level comma expression in array subscript changed meaning in C++23 [-Wcomma-subscript]


I have overloaded the 2D subscript operator in one of my classes. And for that I use the -std=c++23 option to compile the program.

Now when calling this operator, GCC complains:

warning: top-level comma expression in array subscript changed meaning in C++23 [-Wcomma-subscript]
  331 |                 m_characterMatrix[ x1, y1 ] = ch.value( );
      |                 ~~~~~~~~~~~~~~~~~^

So what is this warning for? Should I take it seriously?


Solution

  • The warning is there because the compiler's assumption is that you might have been expecting the pre-C++23 behaviour - that is, the "traditional" comma operator evaluation.
    (While common sense would clearly indicate that you meant to use your overload and there is no problem, computer programs don't possess common sense.)

    You can disable that warning with -Wno-comma-subscript.