Can this be fixed?
It is fixed. Just try with a recent version of GCC.
For example, any g++ version from v12 on (maybe even older) has the issue fixed. v12 was released in 2022, so enough time to update your tools. (Though I still see it in v8).
As far as I can tell, only the C++ front is affected, though I cannot point to the respective PR.