Good question - I don't know, but it can be demonstrated using the Online C++ Compiler:
https://onlinegdb.com/g-czg9Hfu
Click on 'Run' and you get a compiler error. But click on 'Fork this', click on the settings cog button (top right), add -O1 to 'Extra Compiler Flags' and 'Run' again - it builds/runs fine.
The fact it can be persuaded to compile ok is probably a gcc-specific idiosyncrasy; if it didn't compile when it should then it would be a gcc bug.