|
Boost : |
From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2003-05-18 10:30:57
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.
Unfortunately, it's exactly what 'stateless_integer_add' does for the sake
of avoiding warnings; and gcc complains about it. So the line
"return 0; // suppress warnings is wrong." doesn't do what it's supposed
to do: it doesn't suppress warnings. Here is patch that returns another
pointer so that gcc doesn't complain. I'm not sure it's the best way to
choose a non-null pointer, but at least gcc doesn't complain anymore, and
the compilers that needed a return statement still have it.
Index: libs/function/test/stateless_test.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/function/test/stateless_test.cpp,v
retrieving revision 1.6
diff -u -r1.6 stateless_test.cpp
--- libs/function/test/stateless_test.cpp 30 Jan 2003 14:25:00 -0000 1.6
+++ libs/function/test/stateless_test.cpp 18 May 2003 15:25:01 -0000
@@ -24,7 +24,7 @@
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
}
void operator delete(void*, stateless_integer_add*) throw()
Regards,
Guillaume
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk