2012-11-06 14:17:32 +00:00
|
|
|
/*
|
2017-03-06 01:18:16 -05:00
|
|
|
Copyright 2012-2015 Glen Joseph Fernandes
|
|
|
|
(glenjofe@gmail.com)
|
2015-11-09 22:35:34 -05:00
|
|
|
|
2017-03-06 01:18:16 -05:00
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
|
|
(http://www.boost.org/LICENSE_1_0.txt)
|
2015-11-09 22:35:34 -05:00
|
|
|
*/
|
2012-11-06 14:17:32 +00:00
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
2015-11-09 22:35:34 -05:00
|
|
|
#include <boost/smart_ptr/make_shared.hpp>
|
2012-11-06 14:17:32 +00:00
|
|
|
|
|
|
|
class type {
|
|
|
|
public:
|
2017-03-06 01:18:16 -05:00
|
|
|
static unsigned instances;
|
|
|
|
|
|
|
|
type() {
|
2012-11-06 14:17:32 +00:00
|
|
|
if (instances == 5) {
|
|
|
|
throw true;
|
|
|
|
}
|
2017-03-06 01:18:16 -05:00
|
|
|
++instances;
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
2017-03-06 01:18:16 -05:00
|
|
|
|
2012-11-06 14:17:32 +00:00
|
|
|
~type() {
|
2017-03-06 01:18:16 -05:00
|
|
|
--instances;
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
2017-03-06 01:18:16 -05:00
|
|
|
|
2012-11-06 14:17:32 +00:00
|
|
|
private:
|
|
|
|
type(const type&);
|
|
|
|
type& operator=(const type&);
|
|
|
|
};
|
|
|
|
|
2017-03-06 01:18:16 -05:00
|
|
|
unsigned type::instances = 0;
|
2012-11-06 14:17:32 +00:00
|
|
|
|
2015-11-09 22:35:34 -05:00
|
|
|
int main()
|
|
|
|
{
|
2012-11-06 14:17:32 +00:00
|
|
|
try {
|
|
|
|
boost::make_shared<type[]>(6);
|
|
|
|
BOOST_ERROR("make_shared did not throw");
|
|
|
|
} catch (...) {
|
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
|
|
|
try {
|
2012-11-11 19:14:50 +00:00
|
|
|
boost::make_shared<type[][2]>(3);
|
|
|
|
BOOST_ERROR("make_shared did not throw");
|
|
|
|
} catch (...) {
|
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
2012-12-03 05:41:34 +00:00
|
|
|
try {
|
|
|
|
boost::make_shared<type[6]>();
|
|
|
|
BOOST_ERROR("make_shared did not throw");
|
|
|
|
} catch (...) {
|
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
boost::make_shared<type[3][2]>();
|
|
|
|
BOOST_ERROR("make_shared did not throw");
|
|
|
|
} catch (...) {
|
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
2012-11-11 19:14:50 +00:00
|
|
|
try {
|
|
|
|
boost::make_shared_noinit<type[]>(6);
|
|
|
|
BOOST_ERROR("make_shared_noinit did not throw");
|
|
|
|
} catch (...) {
|
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
boost::make_shared_noinit<type[][2]>(3);
|
2012-11-06 14:17:32 +00:00
|
|
|
BOOST_ERROR("make_shared_noinit did not throw");
|
|
|
|
} catch (...) {
|
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
2014-01-23 20:40:46 -08:00
|
|
|
try {
|
|
|
|
boost::make_shared_noinit<type[6]>();
|
|
|
|
BOOST_ERROR("make_shared_noinit did not throw");
|
2014-01-28 02:27:49 -08:00
|
|
|
} catch (...) {
|
2014-01-23 20:40:46 -08:00
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
boost::make_shared_noinit<type[3][2]>();
|
|
|
|
BOOST_ERROR("make_shared_noinit did not throw");
|
2014-01-28 02:27:49 -08:00
|
|
|
} catch (...) {
|
2014-01-23 20:40:46 -08:00
|
|
|
BOOST_TEST(type::instances == 0);
|
|
|
|
}
|
2012-11-06 14:17:32 +00:00
|
|
|
return boost::report_errors();
|
|
|
|
}
|