This is the mail archive of the gcc@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: CVS head (gcc-3.4), new warning for 'no return in templates'


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


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