From 9960d9f395b79ee860e39064cd46961f76d2cb55 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 13 Feb 2017 08:15:44 -0800 Subject: [PATCH] Don't construct string_view|string_ref from rvalue string. That way lies pain --- include/boost/utility/string_ref.hpp | 7 +++++++ include/boost/utility/string_view.hpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/include/boost/utility/string_ref.hpp b/include/boost/utility/string_ref.hpp index 5acf346..ea47f76 100644 --- a/include/boost/utility/string_ref.hpp +++ b/include/boost/utility/string_ref.hpp @@ -92,6 +92,13 @@ namespace boost { basic_string_ref(const std::basic_string& str) : ptr_(str.data()), len_(str.length()) {} +#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 + basic_string_ref(std::basic_string&& str) + = delete; +#endif + BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT : ptr_(str), len_(len) {} diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index 410bd88..935dcb6 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -95,6 +95,13 @@ namespace boost { 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 + basic_string_view(std::basic_string&& str) + = delete; +#endif + BOOST_CONSTEXPR basic_string_view(const charT* str) : ptr_(str), len_(traits::length(str)) {}