Author Topic: gcc attribute: warn_unused_result  (Read 17957 times)

Offline r.stiltskin

  • Multiple posting newcomer
  • *
  • Posts: 48
gcc attribute: warn_unused_result
« on: December 05, 2011, 05:17:04 pm »
gcc is supposed to warn, by default, if a program ignores the return value of a function declared with __attribute_warn_unused_result__.  And indeed, if I write any simple program including <stdio.h> and calling fscanf (but ignoring its return value), CodeBlocks will issue the appropriate warning.  But if I compile that same program in a terminal window with simply:
gcc myprog.c
there is no warning.  As far as I can see, I shouldn't have to supply any options to get the warning.

My question is: is CodeBlocks doing something special to produce that "default" warning?  How can I see the exact compiler command that CodeBlocks is using?

I'm using Ubuntu 10.04 with gcc 4.4.3 (from Ubuntu repository) and CodeBlocks svn build rev 7548 (also from the Ubuntu repository).   Also tried compiling in Debian Lenny on the command line and I don't get the warnings there either.

zabzonk

  • Guest
Re: gcc attribute: warn_unused_result
« Reply #1 on: December 05, 2011, 05:23:23 pm »
Enable the build log in Settings|Compiler And Debugger|Build Options. Make sure you check "always output full command  line."

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: gcc attribute: warn_unused_result
« Reply #2 on: December 05, 2011, 05:27:22 pm »
It's not a default warning, at least in the version of GCC you're using. The command line switch "-Wall", which is part of Code::Blocks' default project config, enables this warning among others.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline r.stiltskin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: gcc attribute: warn_unused_result
« Reply #3 on: December 05, 2011, 06:20:58 pm »
Aha!  Thanks.

No, it's not the -Wall option -- i had already tried that, along with -Wextra and -pedantic, and none of them helped.  Strangely, it's the optimization flag.   CodeBlocks is compiling with -O2, and when I add that to my command line it produces the "ignoring return value" warning.  It  turns out that the lowest optimize flag -O produces the warning too.

@Neil: I found the setting in Settings|Compiler|Other Settings where there's a selection box for "Compiler logging: Full command line"