Deuger wont start when build_unflags = -std=gnu++11

Testing esp-wrover-kit debugging on OSX. The project has the following PlatformIO configuration

platform = espressif32
board = esp-wrover-kit
framework = arduino

build_unflags = -std=gnu++11
build_flags = -std=gnu++2a

monitor_speed = 9600
monitor_filters = esp32_exception_decoder

build_type = debug
debug_tool = ftdi
debug_speed = 9600
debug_init_break = break setup

Using a simple Hello World project. If build_unflags = -std=gnu++11 is removed from the above configuration, the debugger stops at the breakpoint as expected. But c++17 functions cannot be compiled.

But if build_unflags = -std=gnu++11 is included, the debugger initialization fails with:

Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway…
Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01

The reason why build_unflags is included is to support c++17 functions such as:

inline variables
std::optional is a template class

Why does JTAG fail with the setting build_unflags = -std=gnu++11, what would be the recommended solution to solve it?

debug_tool = ftdi

possibly ftdi is dependent on ++11, and once removed, is not supported any more. If that is the case, maybe option is to switch to different debugger, that supports ++17

Another note, when PlatformIO.ini has following configuration:

; build_unflags = -std=gnu++11 // commented out
build_flags = -std=gnu++2a

VSCode IDE detects optional template and locates in the .platformio/packages as expected.

Yet, Compiler throws an error.

error: ‘optional’ does not name a type; did you mean ‘optind’?

Noted that during compilation .platformio/packages builds following:

  1. .platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/5.2.0
    Do not have optional template

  2. .platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/12.2.0
    Do have optional template

  3. .platformio/packages/toolchain-xtensa-esp32@8.4.0+2021r1/xtensa-esp32-elf/include/c++/8.4.0
    Do have optional template

  4. .platformio/packages/toolchain-xtensa-esp32@8.4.0+2021r2-patch5/xtensa-esp32-elf/include/c++/8.4.0
    Do have optional template

When PlatformIO.ini has gnu++ removed

build_unflags = -std=gnu++11

Compilation is successful

So it looks like, that for some reason compiler picks the first toolchain-xtensa that does not have optional template.