From 4cc247cc700f105ea69a4427e3527cdbd4394257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 15 May 2021 12:02:02 +0200 Subject: [PATCH] Use constexpr StringRef instance for unprintable strings --- src/catch2/catch_tostring.cpp | 13 ------------- src/catch2/catch_tostring.hpp | 4 ++-- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/catch2/catch_tostring.cpp b/src/catch2/catch_tostring.cpp index 8b0ffe01..775d4a77 100644 --- a/src/catch2/catch_tostring.cpp +++ b/src/catch2/catch_tostring.cpp @@ -5,12 +5,6 @@ // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -# pragma clang diagnostic ignored "-Wglobal-constructors" -#endif - #include #include @@ -24,8 +18,6 @@ namespace Catch { namespace Detail { - const std::string unprintableString = "{?}"; - namespace { const int hexThreshold = 255; @@ -237,8 +229,3 @@ std::string StringMaker::convert(double value) { } } // end namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp index d0f799a0..da2758ce 100644 --- a/src/catch2/catch_tostring.hpp +++ b/src/catch2/catch_tostring.hpp @@ -30,7 +30,7 @@ namespace Catch { namespace Detail { - extern const std::string unprintableString; + constexpr StringRef unprintableString = "{?}"_sr; std::string rawMemoryToString( const void *object, std::size_t size ); @@ -59,7 +59,7 @@ namespace Catch { std::enable_if_t< !std::is_enum::value && !std::is_base_of::value, std::string> convertUnstreamable( T const& ) { - return Detail::unprintableString; + return std::string(Detail::unprintableString); } template std::enable_if_t<