Boost logo

Boost :

From: Marco Manfredini (marco_at_[hidden])
Date: 2000-07-17 11:07:39


> -----Ursprungliche Nachricht-----
> Von: Beman Dawes [mailto:beman_at_[hidden]]
> Gesendet: Sonntag, 16. Juli 2000 16:35
> An: Boost.org mailing list
> Betreff: [boost] Exception specifications in smart_ptr.hpp
>
[SNIP]
> In reviewing the log file from the regression test, I noticed
> the following
> from both Borland 5.4 and 5.5:
>
> Warning W8026 c:/boost/site/libs/smart_ptr/smart_ptr_test.cpp
> 61: Functions
> with exception specifications are not expanded inline in
> function main()
>
> smart_ptr.hpp has throw specifiers on a number of
> time-critical inline
> functions such as dereferencing:
>
> T& operator*() const throw() { return *ptr; }
>
> It's a disaster if these aren't inlined.
>

Just for curiosity

The following (for example)

template<class T>
struct ptr
{
        T* v;
        ptr(T* _v) : v(_v) {}
        T& operator*() const throw() { return *v; }
};

int main(int argc, char* argv[])
{
        ptr<char> nullp(NULL);
        char& pc=*nullp;
        char c=pc;
        return 0;
}

crashes, as expected, in the line "char c=pc" (MSVC6).

Is the throw() declaration meaningful, since some hidden paragraph in the
standard allows a compiler to throw if he detects the construction of a null
reference? I have only seen the obvious bag yet, saying the behaviour is
'undefined'.
(And the same goes to the construction of references in that they shall
always bind a valid object or function (8.3.3.4), which can't be guaranteed
with pointers, but that's another thing)

I haven't seen any instructions yet, that 'undefined' operations shall throw
exceptions. Couldn't there be an option to detect them? Like:

T& operator *() const throw()
{
#if BOOST_DETECT_UNDEFINED_OPS
        if (v==NULL) throw undefined_behaviour();
#endif
        return *v;
}

--------
greetings
Marco Manfredini


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