Arduino can be built with C20/C++20 or C17/C++17 by switching to the latest gcc-arm-none-eabi. Below shows 2 different ways one using arduino-cli and the other using a Makefile included in this repo.
When compiling for UNO R4 WiFi, UNO R3, Nano, or Mega on my MacBook Pro M2, I get an "avr-g++: internal compiler error: Killed: 9 (program cc1plus)" error: FQBN ...