Make sure you have "Show verbose output during: compilation" checked in the Arduino preferences, and look carefully at how the compiler is invoked. See if that yields any clues. The compiler options are determined partially by the board support package, so it's significant which board you're compiling for. Compiling for ESP32 (M5Stick), I have these flags in my command line:
...
-Wno-error=unused-function
-Wno-error=unused-variable
-Wno-error=deprecated-declarations
-Wno-unused-parameter
So it looks like this particular board support package is explicitly disabling the unused-variable warning and others.