This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Control reaches end of non-void function: why only a warning?


> Not a bad idea, but in many situations, I am compiling a large
> project whose code generates many warnings, and turning them all
> into errors would be unworkable.

Use -Werror with only the specific warning option (-Wreturn-type) turned on.
Fix the warnings, remove -Werror and add back in the other warning options.

> I have patched my copy of the gcc sources to turn this warning
> into an error, but I'm still curious to see an example of when it
> is useful to knowingly allow the control flow to leave a function
> with an undefined return value.

There could be a function with a control flow that returns something useful
in one path and something meaningless in another. Or a function calls
another function that never returns (exit example).  It is more important
for a compiler to follow the language standard and accept valid source than
it is to have a compiler that tries to enforce good programming practises
and design. There are plenty of static analysis tools for checking c
programs available (lint/splint/etc).

Regards,

Ryan Mansfield


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]