This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: failure to warn about an obvious error
Martin> As you probably know, it is very tricky to reliably tell whether a
Martin> function can "fall off the end". For example,
Martin> #include <vector>
Martin> std::vector<int> f(bool b) {
Martin> if (b)
Martin> return std::vector<int>();
Martin> }
Martin> is well-defined if this function is never invoked with "false".
Indeed, I do know. Personally, I would consider a warning from the
example above to be a Good Thing. However, I agree with you that
there are some reasonable programs that a compiler cannot detect as
probably erroneous.
What do you think about the idea of warning if a function is defined
as returning a value but there is no return statement anywhere in it
(and the function is not main)? That would catch lots of common cases.