This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Don't warn about missing return statement if noreturn function is called in template (PR c++/30988)
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Sun, 18 Nov 2007 13:37:50 -0800
- Subject: Re: [C++ PATCH] Don't warn about missing return statement if noreturn function is called in template (PR c++/30988)
- References: <20071117172024.GD5451@devserv.devel.redhat.com>
Jakub Jelinek wrote:
> Even if a function is called with type dependent args, we might know
> that it is a noreturn function which normally surpresses warning about
> missing return stmt. Though IMHO it is better to issue a false positive
> warning than not warn about missing return.
Yes, the false positive is preferred in this situation, since noreturn
functions are the exception, not the rule.
I'm surprised we're using current_function_returns_abnormally in this
way; it looks like we'll not complain about:
int f() {
if (something)
abort ();
}
which I suspect is not what people want...
Other front ends with which I am familiar do some very limited
reachability analysis to determine whether or not to issue a warning.
(In particular, they would warn about this case, and would warn even if
"something" were replaced by "true".)
But, we are where we are...
> Regtested on x86_64-linux, ok for trunk?
This is OK in concept, but...
> + if (cfun)
> + {
> + if (TREE_CODE (fn) == FUNCTION_DECL
> + && TREE_THIS_VOLATILE (fn))
> + current_function_returns_abnormally = 1;
> + else if (TREE_CODE (fn) == OVERLOAD)
> + {
> + bool all_noreturn = true;
> + while (fn)
> + {
> + if (TREE_CODE (OVL_CURRENT (fn)) == FUNCTION_DECL
> + && !TREE_THIS_VOLATILE (OVL_CURRENT (fn)))
> + all_noreturn = false;
> + fn = OVL_NEXT (fn);
> + }
> + if (all_noreturn)
> + current_function_returns_abnormally = 1;
> + }
> + }
(1) in the OVERLOAD case, we should exit the loop immediately once we
find a function that is not no-return.
(2) OVL_CURRENT/OVL_NEXT are designed so that you can use them on both
OVERLOADs and FUNCTION_DECLs. In particular, something like this:
while (fn)
{
f = OVL_CURRENT (fn);
if (!TREE_THIS_VOLATILE (f))
break;
fn = OVL_NEXT (fn);
}
if (!fn)
current_function_returns_abnormally = 1;
OK with a change to that style.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713