Currently gcc is intentionally patched to alter the default optimization level from -O0 to -O1. This is done in package.yml at the line '%patch -p1 < $pkgfiles/optimize-at-least-some.patch'. A comment in this file indicates the purpose as 'without at least -O1 optimizations, many security checks just do not work so default to at least O1'. Without knowing the security checks that require this setting, it certainly seems a worthy goal. However, this does now mean that gcc behaves differently to what is indicated in the man page supplied with the distribution as well as the typical behavior in most other distributions and the on-line gcc documentation (including no doubt countless programming tutorial pages).
This means that unless users explicitly set -O0 for debug builds, certain optimizations that make debugging difficult (such as elimination of variables) will occur. Depending on the build system in use, and the users expectations, there is the potential for this to be very difficult to diagnose and correct. Bearing in mind that when working on large open source projects it is normal to just follow the build instructions provided and not attempt to understand the intricacies of the build system in use.
For example, if a user is working on a project using a build system based on cmake, then the expected command to generate a debug build would include the option '-DCMAKE_BUILD_TYPE=Debug'. Unless the CMakeLists.txt file includes custom debug options, this will result in only the gcc option '-g' being emitted. With the default optimization changed to -O1, unnecessary variables will be optimized out, leading to a sub-optimal debug experience. To find out the reason for this undesirable behavior the user will probably inspect the compile commands output by cmake and will check with the gcc man page or on-line documentation to see what optimization should result - they will be misled. No matter how deeply they inspect the complicated network of makefiles generated by cmake they will not find the cause, which will only be found by explicitly setting -O0.
The solution is to remove the patch and restore the expected behavior of gcc. If, for the purpose of security checks, other optimization levels are required for package code, then this should be set explicitly in the build system for the respective packages not in gcc itself where it will affect all subsequent software build within Solus.