From 7f7a29bce133f4cc878893647fd26eb67fbb40a1 Mon Sep 17 00:00:00 2001 From: Rolan Reznik Date: Tue, 26 Nov 2019 12:35:05 +0200 Subject: [PATCH 1/2] Added possibility to force explicit conversion of string from char. (#172) i.e. string/string_view constructors from char* can be marked as explicit. #170 --- include/etl/cstring.h | 2 +- include/etl/platform.h | 7 +++++++ include/etl/string_view.h | 2 +- include/etl/u16string.h | 2 +- include/etl/u32string.h | 2 +- include/etl/wstring.h | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/etl/cstring.h b/include/etl/cstring.h index bbd689f4..5e700536 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -114,7 +114,7 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the string. //************************************************************************* - string(const value_type* text) + ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text) : istring(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + etl::char_traits::length(text)); diff --git a/include/etl/platform.h b/include/etl/platform.h index 76182726..9fee1345 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -53,6 +53,7 @@ SOFTWARE. #undef ETL_NO_LARGE_CHAR_SUPPORT #undef ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED #undef ETL_STD_ATOMIC_SUPPORTED +#undef ETL_FORCE_EXPLICIT_STRING_CONVERSION_FROM_CHAR // Determine the bit width of the platform. #define ETL_PLATFORM_16BIT (UINT16_MAX == UINTPTR_MAX) @@ -102,4 +103,10 @@ SOFTWARE. #define ETL_NOEXCEPT_EXPR(expression) #endif +#if ETL_FORCE_EXPLICIT_STRING_CONVERSION_FROM_CHAR + #define ETL_EXPLICIT_STRING_FROM_CHAR explicit +#else + #define ETL_EXPLICIT_STRING_FROM_CHAR +#endif + #endif diff --git a/include/etl/string_view.h b/include/etl/string_view.h index b8ada876..a7c46232 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -137,7 +137,7 @@ namespace etl //************************************************************************* /// Construct from T*. //************************************************************************* - ETL_CONSTEXPR basic_string_view(const T* begin_) + ETL_EXPLICIT_STRING_FROM_CHAR ETL_CONSTEXPR basic_string_view(const T* begin_) : mbegin(begin_), mend(begin_ + TTraits::length(begin_)) { diff --git a/include/etl/u16string.h b/include/etl/u16string.h index 5722716c..03d97f56 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -114,7 +114,7 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u16string. //************************************************************************* - u16string(const value_type* text) + ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + etl::char_traits::length(text)); diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 16826051..a8f9b769 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -114,7 +114,7 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u32string. //************************************************************************* - u32string(const value_type* text) + ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + etl::char_traits::length(text)); diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 3237f6b8..16d59ae4 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -115,7 +115,7 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the wstring. //************************************************************************* - wstring(const value_type* text) + ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + etl::char_traits::length(text)); From cbdc8a929952036bcf6593aa4ba601e10b4feee9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 26 Nov 2019 10:57:45 +0000 Subject: [PATCH 2/2] Updated version numbers --- include/etl/version.h | 4 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 5 ++ test/vs2017/etl.vcxproj | 100 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index 7d5e28dd..789badbb 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 37 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_MINOR 38 +#define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 11c436b3..4d8a97f2 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "14.37.2", + "version": "14.38.0", "authors": { "name": "John Wellbelove", "email": "" diff --git a/library.properties b/library.properties index 3be3860c..dc899c5a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=14.37.2 +version=14.38.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 6c265cf2..d0a46c7e 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +14.38.0 +Added optional to force string and string_view construction from character +pointers to be explicit. + =============================================================================== 14.37.2 Added assert.h include to memory.h diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index 24111577..9103eac2 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -1,6 +1,14 @@  + + Debug Clang + Win32 + + + Debug Clang + x64 + Debug LLVM Win32 @@ -62,6 +70,12 @@ llvm Unicode + + Application + true + v141_clang_c2 + Unicode + Application true @@ -74,6 +88,12 @@ v141 Unicode + + Application + true + v141 + Unicode + Application true @@ -121,12 +141,18 @@ + + + + + + @@ -156,6 +182,11 @@ true \$(IntDir) + + false + true + \$(IntDir) + true true @@ -164,6 +195,10 @@ true true + + true + true + true true @@ -233,6 +268,30 @@ "$(OutDir)etl.exe" + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../../unittest-cpp/UnitTest++/;../../include;../../include/etl/c;../../test + + + false + stdcpp17 + false + FullDebug + Default + + + Console + false + + + "$(OutDir)etl.exe" + + @@ -275,6 +334,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../include/etl/c;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -705,8 +785,10 @@ false false false + false false false + false false false false @@ -728,8 +810,10 @@ false false + false false false + false false false false @@ -746,40 +830,50 @@ false false + false false false + false false false false false + false false false + false false false false false + false false false + false false false false false + false false false + false false false false false + false false false + false false false @@ -791,8 +885,10 @@ false false + false false false + false false false false @@ -803,8 +899,10 @@ true false false + false false false + false false false @@ -824,8 +922,10 @@ false false + false false false + false false false false