CVS head (gcc-3.4), new warning for 'no return in templates'

Andrew Pollard andrewp@andypo.net
Tue Dec 31 04:47:00 GMT 2002


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



More information about the Gcc mailing list