diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index 762a9f4..bde7b7a 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -1202,7 +1202,7 @@ class basic_static_string BOOST_STATIC_STRING_CPP14_CONSTEXPR basic_static_string(const_pointer s) { - assign(s); + assign(s, s + traits_type::length(s)); } /** Constructor. @@ -1373,7 +1373,7 @@ class basic_static_string basic_static_string& operator=(const_pointer s) { - return assign(s); + return assign(s, s + traits_type::length(s)); } /** Assign to the string. diff --git a/test/constexpr_tests.hpp b/test/constexpr_tests.hpp index 3517488..7c6ab12 100644 --- a/test/constexpr_tests.hpp +++ b/test/constexpr_tests.hpp @@ -67,6 +67,22 @@ bool testConstantEvaluation() { #ifdef BOOST_STATIC_STRING_CPP20 + + // Check construction in a constexpr context + constexpr basic_static_string s("hello"); + static_assert(s.size() == 5); + static_assert(s == "hello"); + + // Check assignment in a constexpr context + constexpr auto s2 = + []() + { + basic_static_string s("hello"); + s = "world"; + return s; + }(); + static_assert(s2 == "world"); + // c++20 constexpr tests cstatic_string a; cstatic_string b(1, 'a');