Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2002-12-04 07:53:44


On Tue, 03 Dec 2002 20:55:02 -0500, David Abrahams
<dave_at_[hidden]> wrote:

>
>I'd like a macro to detect that a compiler requires a return value
>even when no paths return from a function. Example:
>
> int f()
> {
> throw "hello";
> };
>
>If this fails to compile, we may need to add a dummy "return 0;" at
>the end.

I'm a little surprised by this question. Are you saying that *no*
paths return a value and you declare the function as non void?

Maybe you were referring to a situation like this?

  // The throw is conditional, and there's at
  // least one path that does return a value
  //
  template <typename ExceptionT>
  void do_throw(ExceptionT const & ex) { throw ex; }

  int f() {
    for ( ...)
      if (...)
        return somevalue;

    do_throw( some_exception() );
  }

Genny.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk