From: Jonathan Wakely Date: Wed, 12 Oct 2016 11:20:35 +0000 (+0100) Subject: Add missing return to uninitialized_default_construct_n X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=08a53a2eda8886d406c497595d57ba09aaf5893e;p=gcc.git Add missing return to uninitialized_default_construct_n * include/bits/stl_uninitialized.h (__uninitialized_default_novalue_n_1): Add missing return. * testsuite/20_util/specialized_algorithms/memory_management_tools/ 1.cc: Check return values of uninitialized_xxx_n algorithms. From-SVN: r241033 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b11d1123a23..c02bbf03a9a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2016-10-12 Jonathan Wakely + * include/bits/stl_uninitialized.h + (__uninitialized_default_novalue_n_1): Add missing return. + * testsuite/20_util/specialized_algorithms/memory_management_tools/ + 1.cc: Check return values of uninitialized_xxx_n algorithms. + * libsupc++/nested_exception.h (throw_with_nested): Remove return. * doc/xml/manual/intro.xml: Document LWG 2442 status. diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h index ef2e584c1b3..07370c90aab 100644 --- a/libstdc++-v3/include/bits/stl_uninitialized.h +++ b/libstdc++-v3/include/bits/stl_uninitialized.h @@ -705,8 +705,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template static _ForwardIterator __uninit_default_novalue_n(_ForwardIterator __first, _Size __n) - { - } + { return std::next(__first, __n); } }; // __uninitialized_default_novalue diff --git a/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc b/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc index 84a68579344..a86e61a2234 100644 --- a/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc +++ b/libstdc++-v3/testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc @@ -74,15 +74,17 @@ void test02() void test03() { char test_data[] = "123456"; - std::uninitialized_default_construct_n(std::begin(test_data), 6); + auto end = std::uninitialized_default_construct_n(std::begin(test_data), 6); VERIFY(std::string(test_data) == "123456"); + VERIFY( end == test_data + 6 ); } void test04() { char test_data[] = "123456"; - std::uninitialized_value_construct_n(std::begin(test_data), 6); - VERIFY(std::string(test_data, 6) == std::string("\0\0\0\0\0\0", 6)); + auto end = std::uninitialized_value_construct_n(std::begin(test_data), 5); + VERIFY(std::string(test_data, 6) == std::string("\0\0\0\0\0" "6", 6)); + VERIFY( end == test_data + 5 ); } void test05() @@ -112,8 +114,9 @@ void test07() del_count = 0; DelCount* x = (DelCount*)malloc(sizeof(DelCount)*10); for (int i = 0; i < 10; ++i) new (x+i) DelCount; - std::destroy_n(x, 10); + auto end = std::destroy_n(x, 10); VERIFY(del_count == 10); + VERIFY( end == x + 10 ); del_count = 0; free(x); } @@ -127,7 +130,8 @@ void test08() std::uninitialized_move(source.begin(), source.end(), target); for (const auto& x : source) VERIFY(!x); for (int i = 0; i < 10; ++i) VERIFY(bool(*(target+i))); - std::destroy_n(target, 10); + auto end = std::destroy_n(target, 10); + VERIFY( end == target + 10 ); free(target); } @@ -137,10 +141,13 @@ void test09() for (int i = 0; i < 10; ++i) source.push_back(std::make_unique(i)); std::unique_ptr* target = (std::unique_ptr*)malloc(sizeof(std::unique_ptr)*10); - std::uninitialized_move_n(source.begin(), 10, target); + auto end = std::uninitialized_move_n(source.begin(), 10, target); + VERIFY( end.first == source.begin() + 10 ); + VERIFY( end.second == target + 10 ); for (const auto& x : source) VERIFY(!x); for (int i = 0; i < 10; ++i) VERIFY(bool(*(target+i))); - std::destroy_n(target, 10); + auto end2 = std::destroy_n(target, 10); + VERIFY( end2 == target + 10 ); free(target); } @@ -156,7 +163,8 @@ void test11() { char* x = (char*)malloc(sizeof(char)*10); for (int i = 0; i < 10; ++i) new (x+i) char; - std::destroy_n(x, 10); + auto end = std::destroy_n(x, 10); + VERIFY( end == x + 10 ); free(x); } @@ -285,10 +293,12 @@ void test19() { char test_source[] = "123456"; char test_target[] = "000000"; - std::uninitialized_move_n(std::begin(test_source), - 6, - test_target); + auto end = std::uninitialized_move_n(std::begin(test_source), + 6, + test_target); VERIFY(std::string(test_target) == "123456"); + VERIFY( end.first == test_source + 6 ); + VERIFY( end.second == test_target + 6 ); } int main()