cgcccompiler-warnings

Make warn_unused_result applied to all function with GCC


Is it possible to tell GCC to use warn_unused_result flag for all function even not having the corresponding attribute? Because if I can forget to check for return value, I can also forget to add the GCC specific attribute.

I've seen it to be possible with some other compilers.


Solution

  • No, you can only tell gcc to ignore all warn_unused_result flags with -Wno-unused-result but the respective -Wunused-result only sets the default (to warn only on flags). Compiling with -Wall -Wextra -pedantic should have triggered a warning if it can be activated but it doesn't, so it cannot.

    Besides that, I wonder why you would want this, it is not that uncommon to ignore the result of functions, and all libraries are likely to produce tons of warnings.