Boost logo

Boost :

From: Stefan Seefeld (seefeld_at_[hidden])
Date: 2007-05-01 09:48:27


Andrew Koenig wrote:
>> Isn't it odd that this nonsense is legal c++?
>
> Yes, sort of. Consider:
>
> double foo(blah blah blah) {
> blah blah blah
> if (x >= 0)
> return std::sqrt(x);
> throw std::domain_error("x was negative in foo");
> }
>
> Here static analysis can tell you that control can never reach the }. But
> what if we put the throw into a separately compiled function?
>
> if (x >= 0)
> return std::sqrt(x);
> throw_domain_error("x was negative in foo");
>
> Now the programmer may know, even though the compiler cannot, that control
> still cannot reach the }. What would have standard do? Force the
> programmer to insert a return statement that the programmer knows can never
> be executed?

Indeed, this can introduce a real dilemma. We have such code, and there isn't
an obvious solution: If we put in such a return statement to make one compiler
happy, another will complain because it correctly figured out by static analysis
that the statement isn't reachable.

Ah well, the joy of portable programming.

Regards,
                Stefan

-- 
      ...ich hab' noch einen Koffer in Berlin...

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