Add tests to ensure that string_view|ref from rvalue fails (whenever it can)

This commit is contained in:
Marshall Clow 2017-02-13 10:25:04 -08:00
parent 9960d9f395
commit 00f02167e3
5 changed files with 65 additions and 8 deletions

View File

@ -95,7 +95,7 @@ namespace boost {
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
// Constructing a string_ref from a temporary string is a bad idea
template<typename Allocator>
basic_string_ref(std::basic_string<charT, traits, Allocator>&& str)
basic_string_ref( std::basic_string<charT, traits, Allocator>&&)
= delete;
#endif

View File

@ -91,14 +91,13 @@ namespace boost {
#endif
template<typename Allocator>
basic_string_view(const std::basic_string<charT, traits,
Allocator>& str) BOOST_NOEXCEPT
basic_string_view(const std::basic_string<charT, traits, Allocator>& str) BOOST_NOEXCEPT
: ptr_(str.data()), len_(str.length()) {}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
// Constructing a string_view from a temporary string is a bad idea
template<typename Allocator>
basic_string_view(std::basic_string<charT, traits, Allocator>&& str)
basic_string_view( std::basic_string<charT, traits, Allocator>&&)
= delete;
#endif

View File

@ -27,9 +27,11 @@ test-suite utility
[ run ../operators_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
[ compile result_of_test.cpp ]
[ run ../shared_iterator_test.cpp ]
[ compile-fail string_ref_from_rvalue.cpp ]
[ run string_ref_test1.cpp unit_test_framework ]
[ run string_ref_test2.cpp unit_test_framework ]
[ run string_ref_test_io.cpp unit_test_framework ]
[ compile-fail string_view_from_rvalue.cpp ]
[ run string_view_test1.cpp unit_test_framework ]
[ run string_view_test2.cpp unit_test_framework ]
[ run string_view_test_io.cpp unit_test_framework ]

View File

@ -0,0 +1,28 @@
/*
Copyright (c) Marshall Clow 2017.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
For more information, see http://www.boost.org
*/
#include <iostream>
#include <algorithm>
#include <string>
#include <boost/utility/string_ref.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
#error "Unsupported test"
#endif
#include "boost/test/minimal.hpp"
std::string makeatemp() { return "abc"; }
int test_main(int, char **)
{
boost::basic_string_ref<char> sv(makeatemp());
return 0;
}

View File

@ -0,0 +1,28 @@
/*
Copyright (c) Marshall Clow 2017.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
For more information, see http://www.boost.org
*/
#include <iostream>
#include <algorithm>
#include <string>
#include <boost/utility/string_view.hpp>
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
#error "Unsupported test"
#endif
#include "boost/test/minimal.hpp"
std::string makeatemp() { return "abc"; }
int test_main(int, char **)
{
boost::basic_string_view<char> sv(makeatemp());
return 0;
}