Removing Compiler Flag -Wno-unused-result

- GCC doesn't warn about unused return values.
-Wno-unused-resultβ what is this, can I remove it safely, and could it cause other problems?

- Check carefully so as not to break other things.

- GCC keeps suppressing warnings about unused results.

- nice warnings and a solution to the mystery.
Honestly, I don't know where to start. As I usually do in this kind of situation, let's try something and see what happens.
Stage 1 - What does the flag mean?
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunused-result
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunused-result
Ok, then what is the attribute warn_unused_result?
https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-warn_005funused_005fresult
https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-warn_005funused_005fresult
Ok, so the compiler will yell for unused return values for functions with the attribute, but when we use -Wno-unused-result, it suppresses the warning.
Stage 2 - I need a plan, but I donβt have a plan.
Hmm, how do I track down which functions have that specific attribute? What if I just let the compiler do the work and throw an error if there is one? Where to start? Maybe from the most recent commit? This is what I did:
** On every compile attempt: removed -Wno-unused-result and added -Wunused-result explicitly.
- Removed the flag on the most recent commit and compiled with
-Wunused-result, it compiled successfully. - What about a year ago? Huh, it compiles successfully as well.
- Why is it there, then? When was this flag added? β> use
git log --followto track where it starts. It was the commitc5494ac06(2015-11-21). It was refactored once on commit62d7164d3(2017-01-23). - To see why it's used, I need to spot it β let the compiler do the work. β> ??? Why does it compile successfully on both
c5494ac06and62d7164d3? - After looking closely at
CMakeLists.txt, I found-Werroris set for non-MSVC whenSTOP_ON_WARNING=ON. β> I guess it's preventative, then? - I still need to be careful β> so I tested the first commit of each year from 2023 to 2026. β> all good!
Stage 3 - Run CI & submit PR
Done and merged β

- I didn't know how to build with a specific compiler before, and I learned how through this journey.
- I learned how to use docker and how to write Dockerfile.
- I learned various git commands and flags:
git grep,git log --follow,git log --before,git log --oneline, andgit show. - I learned that the prefix
-Wenables a warning and-Wnodisables it for compiler flags generally. - I prefer building from the terminal (also for git) because IDE setup itself sometimes drives me crazy (it's not really intuitive for me). But I'm going to try setting up the configuration in CLion later too, because this feels like a good chance to learn, otherwise I might never do it.
- So I learned the compilation pipeline is: configure β generate β build. Configure and generate happen in one call, e.g.,
cmake -B build-dir .... The build step happens when we callcmake --build build-dir ...ormake/ninjadirectly. - I learned what a "generator" is.
CMakeLists.txtcontains human-readable text, and the generator creates a lower-level file containing the "plan" derived from it. - Before, I used to just memorize commands and flags. But now I'm learning them one by one, and it's quite interesting.
CMake flags:
-Band-Gfor the build target directory and the specific generator, respectively.-DCMAKE_C_COMPILERand-DCMAKE_CXX_COMPILERfor the path to the specific compilers. The build target directory name is up to the user, and once set, I can just build withcmake --build <target_dir>.