Manuel López-Ibáñez - Re: [PING^2] PR 29521 Confusing warning for return with expression in fu (original) (raw)

This is the mail archive of the gcc-patches@gcc.gnu.orgmailing list for the GCC project.

On 11/02/07, Joseph S. Myers joseph@codesourcery.com wrote:

On Sun, 11 Feb 2007, Manuel López-Ibáñez wrote:

Will the following satisfy you?

  current_function_returns_null = 1;
  •   if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  •      pedwarn ("%<return%> with a value, in function returning void");
  • if (pedantic)
  •    pedwarn ("ISO C forbids %<return%> with expression in function

returning void");

  • else if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  •     pedwarn ("%<return%> with non-void value, in function

returning void");

Should the last pedwarn be a normal warning?

No, both should be pedwarns but the checks should be the other way round. First if the type is non-void give that pedwarn, otherwise if void and pedantic give the "ISO C" one.