From f3bacd708a2d35572f73c8ff030fdb7a29d3312e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 5 Jul 2023 14:43:46 +0200 Subject: [PATCH] cleanup: make Name and STRING_WITH_LEN usable in constexpr --- include/m_string.h | 2 +- sql/sql_type.h | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/include/m_string.h b/include/m_string.h index 6a645b20a7f..28ad9ee7c88 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -201,7 +201,7 @@ extern ulonglong strtoull(const char *str, char **ptr, int base); #ifdef __cplusplus #include -template inline const char *_swl_check(T s) +template inline constexpr const char *_swl_check(T s) { static_assert(std::is_same::value || std::is_same::value, diff --git a/sql/sql_type.h b/sql/sql_type.h index f496914017b..b39157c3706 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -3384,17 +3384,12 @@ public: class Name: private LEX_CSTRING { public: - Name(const char *str_arg, uint length_arg) - { - DBUG_ASSERT(length_arg < UINT_MAX32); - LEX_CSTRING::str= str_arg; - LEX_CSTRING::length= length_arg; - } - Name(const LEX_CSTRING &lcs) - { - LEX_CSTRING::str= lcs.str; - LEX_CSTRING::length= lcs.length; - } + constexpr Name(const char *str_arg, uint length_arg) : + LEX_CSTRING({str_arg, length_arg}) + { } + constexpr Name(const LEX_CSTRING &lcs) : + LEX_CSTRING(lcs) + { } const char *ptr() const { return LEX_CSTRING::str; } uint length() const { return (uint) LEX_CSTRING::length; } const LEX_CSTRING &lex_cstring() const { return *this; }