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.
For GCC, copying from the full list of warnings provided by this tool for your compiler version appears to be the only way to ensure that all warnings are turned on, since (unlike Clang) GCC does not provide -Weverything . The tool appears to parse the actual c.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
You can use the -Werror compiler flag to turn all or some warnings into errors. Show activity on this post. You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning. Unfortunately, in this case there isn't any specific option that covers that warning.
The -pedantic option tells GCC to issue warnings in such cases; -pedantic-errors says to make them errors instead. This does not mean that all non-ISO constructs get warnings or errors. See Options to Request or Suppress Warnings, for more detail on these and related command-line options.
These functions changed semantics in GCC 4.4. Warn whenever a function parameter is assigned to, but otherwise unused (aside from its declaration). To suppress this warning use the unused attribute (see Variable Attributes ). This warning is also enabled by -Wunused together with -Wextra .
To help detect accidental misuses of such arrays GCC issues warnings unless it can prove that the use is safe. See Common Variable Attributes . Warn for cases where adding an attribute may be beneficial.
Do not warn if a caller of a function marked with attribute warn_unused_result (see Function Attributes) does not use its return value. The default is -Wunused-result . Warn whenever a local or static variable is unused aside from its declaration. This option implies -Wunused-const-variable=1 for C, but not for C++.
When there is the potential for this confusion, GCC issues a warning when this flag is specified. To eliminate the warning, add explicit braces around the innermost if statement so there is no way the else can belong to the enclosing if. The resulting code looks like this: This warning is enabled by -Wparentheses .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With