Example:
std::array arr{1,2,3,4,5};
for([[maybe_unused]] int a = -10; auto i : arr)
^^^^^^^^^^^^^^^^
{
std::cout << i + a;
}
This seems to work fine on GCC and Clang, but fails to compile with MSVC: https://godbolt.org/z/reP5vPM6h with the error:
error C2059: syntax error: ':'
error C2143: syntax error: missing ';' before '{'
error C3536: 'i': cannot be used before it is initialized
But for some reason this compiles fine on MSVC, despite I don't think it's legal:
for(int [[maybe_unused]] a = -10; auto i : arr) {}