public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* CVS head (gcc-3.4), new warning for 'no return in templates'
@ 2002-12-31  4:47 Andrew Pollard
  2002-12-31  8:15 ` Gabriel Dos Reis
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Pollard @ 2002-12-31  4:47 UTC (permalink / raw)
  To: gcc


Hi All,

 The following was 'recently' committed....

>2002-12-17  Jason Merrill  <jason@redhat.com>
>
>    * decl.c (finish_function): Also complain about no return in
>    templates.
>    * semantics.c (finish_return_stmt): Also call check_return_expr in
>    templates.
>    * typeck.c (check_return_expr): In a template, just remember that we
>    saw a return.

Which in itself is probably a good change, but I've just noticed (from
the Apache Xalan library), that it causes a warning in the following
case...

template_void_return.cxx:
------------------------------
#include <functional>

template<typename T>
struct A : public std::unary_function<const T*, void> {
    typedef std::unary_function<const T*, void>   BaseClassType;
    typedef typename BaseClassType::argument_type argument_type;
    typedef typename BaseClassType::result_type   result_type;

    result_type
    operator()(argument_type p) const {
        delete p;
    }
};
------------------------------

% gcc34 -Wall -c template_void_return.cxx
template_void_return.cxx: In member function `typename
   std::unary_function<const _Tp*, void>::result_type A<T>::operator()(typename
   std::unary_function<const _Tp*, void>::argument_type) const':
template_void_return.cxx:12: warning: no return statement in function returning
   non-void

But, in this case, couldn't the compiler figure out that 'result_type'
is in fact 'void' anyway, and not warn?

It's not a great problem, since if you change the 'result_type' to be
'void' in the definition of 'operator()' the warning goes away... it's
just 'not quite the STL way' :-)

Andrew.
--
 Andrew Pollard, Brooks-PRI Automation  | home: andrew@andypo.net
670 Eskdale Road, Winnersh Triangle, UK | work: Andrew.Pollard@brooks-pri.com
 Tel/Fax:+44 (0)118 9215603 / 9215660   | http://www.andypo.net

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: CVS head (gcc-3.4), new warning for 'no return in templates'
  2002-12-31  4:47 CVS head (gcc-3.4), new warning for 'no return in templates' Andrew Pollard
@ 2002-12-31  8:15 ` Gabriel Dos Reis
  2002-12-31 11:53 ` Mark Mitchell
  2002-12-31 13:00 ` Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Gabriel Dos Reis @ 2002-12-31  8:15 UTC (permalink / raw)
  To: Andrew Pollard; +Cc: gcc

Andrew Pollard <andrewp@andypo.net> writes:

[...]

| But, in this case, couldn't the compiler figure out that 'result_type'
| is in fact 'void' anyway, and not warn?

No, it can't until instantiation time. 

 Probably, the non-return detection machinery should be changed to
defer warning when it can't determine for sure what the return type is.

-- Gaby

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: CVS head (gcc-3.4), new warning for 'no return in templates'
  2002-12-31  4:47 CVS head (gcc-3.4), new warning for 'no return in templates' Andrew Pollard
  2002-12-31  8:15 ` Gabriel Dos Reis
@ 2002-12-31 11:53 ` Mark Mitchell
  2002-12-31 13:00 ` Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Mitchell @ 2002-12-31 11:53 UTC (permalink / raw)
  To: Andrew Pollard, gcc, jason



--On Tuesday, December 31, 2002 11:44:55 AM +0000 Andrew Pollard 
<andrewp@andypo.net> wrote:

>
> Hi All,
>
>  The following was 'recently' committed....
>
>> 2002-12-17  Jason Merrill  <jason@redhat.com>
>>
>>    * decl.c (finish_function): Also complain about no return in
>>    templates.
>>    * semantics.c (finish_return_stmt): Also call check_return_expr in
>>    templates.
>>    * typeck.c (check_return_expr): In a template, just remember that we
>>    saw a return.
>
> Which in itself is probably a good change, but I've just noticed (from
> the Apache Xalan library), that it causes a warning in the following
> case...

I meant to comment on this patch when I saw it go by -- I think it's a
mistake.  I think it makes little sense to warn about much of anything
in templates due to problems like these; at the very least, we should
only be warning when the return type is non-dependent.

-- 
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: CVS head (gcc-3.4), new warning for 'no return in templates'
  2002-12-31  4:47 CVS head (gcc-3.4), new warning for 'no return in templates' Andrew Pollard
  2002-12-31  8:15 ` Gabriel Dos Reis
  2002-12-31 11:53 ` Mark Mitchell
@ 2002-12-31 13:00 ` Jason Merrill
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2002-12-31 13:00 UTC (permalink / raw)
  To: Andrew Pollard; +Cc: gcc

On Tue, 31 Dec 2002 11:44:55 GMT, Andrew Pollard <andrewp@andypo.net> wrote:

> #include <functional>
>
> template<typename T>
> struct A : public std::unary_function<const T*, void> {
>     typedef std::unary_function<const T*, void>   BaseClassType;
>     typedef typename BaseClassType::argument_type argument_type;
>     typedef typename BaseClassType::result_type   result_type;
>
>     result_type
>     operator()(argument_type p) const {
>         delete p;
>     }
> };
> ------------------------------
>
> % gcc34 -Wall -c template_void_return.cxx
> template_void_return.cxx: In member function `typename
>    std::unary_function<const _Tp*, void>::result_type A<T>::operator()(typename
>    std::unary_function<const _Tp*, void>::argument_type) const':
> template_void_return.cxx:12: warning: no return statement in function returning
>    non-void
>
> But, in this case, couldn't the compiler figure out that 'result_type'
> is in fact 'void' anyway, and not warn?

No; in theory std::unary_function<const T*, void> could be something other
than void for some T due to a specialization.

> It's not a great problem, since if you change the 'result_type' to be
> 'void' in the definition of 'operator()' the warning goes away... it's
> just 'not quite the STL way' :-)

IMO, this instance of "the STL way" is gratuitously clever and obfuscatory.
If you're writing a function that deliberately doesn't return a value, you
should declare it to return void, not some typedef to void, regardless of
templates.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-12-31 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-31  4:47 CVS head (gcc-3.4), new warning for 'no return in templates' Andrew Pollard
2002-12-31  8:15 ` Gabriel Dos Reis
2002-12-31 11:53 ` Mark Mitchell
2002-12-31 13:00 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).