This is the mail archive of the gcc-patches@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: [C++ PATCH] Don't warn about missing return statement if noreturn function is called in template (PR c++/30988)


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


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