ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
Re: [boost] Patch for the Function library
by Giovanni Bajo other posts by this author
May 18 2003 11:46PM messages near this date
Re: [boost] Patch for the Function library | Re: [boost] Patch for the Function library
Guillaume Melquiond <gmelquio@[...].fr>  wrote:

>  According to the paragraph 3.7.3.1-3 of the Standard, an 'operator new'
>  can return a null pointer or throw an exception to report a failed
>  allocation; but it isn't allowed to adopt the two behaviors.

Really? I don't see this specified in that very paragraph. To me, it looks
like it's saying that:

- an allocation function which is declared as throw() must return a null
pointer in case of failure.
- an allocation function which is not declared as throw() can call
new_handler, or, alternatively, throw a std::bad_alloc (or exception derived
from it).

>     void* operator new(std::size_t, stateless_integer_add*)
>     {
>       throw std::runtime_error("Cannot allocate a stateless_integer_add");
>  -    return 0; // suppress warnings
>  +    return (void*)1; // suppress warnings
>     }

Since this allocation function is not declared throw(), it should throw a
std::bad_alloc(), not a runtime_error(). The return value does not make
sense here because of the throw: that statement is never reached. If there
are warnings about the return value, compilers could be improved to at least
shut them off in such situation, or can be simply turned off in any way
(return 0 is ok).

What is the warning you get with GCC?

Instead, I think this is ill-formed because it's throwing an exception which
is not derived from std::bad_alloc(). What is this code supposed to do? If
the goal is disabling new() for stateless_integer_add, why simply you don't
add a protected operator new as member of the class?

Giovanni Bajo

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Guillaume Melquiond
Douglas Gregor
Giovanni Bajo
Guillaume Melquiond
Giovanni Bajo
Guillaume Melquiond
Giovanni Bajo
Guillaume Melquiond
Beman Dawes

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved