summaryrefslogtreecommitdiff
path: root/include/m_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/m_string.h')
-rw-r--r--include/m_string.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/include/m_string.h b/include/m_string.h
index 9e35be404ec..046dc39d13a 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -199,9 +199,22 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
#include <mysql/plugin.h>
-#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
-#define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1))
-#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
+#ifdef __cplusplus
+#include <type_traits>
+template<typename T> inline const char *_swl_check(T s)
+{
+ static_assert(std::is_same<T, const char (&)[sizeof(T)]>::value
+ || std::is_same<T, const char [sizeof(T)]>::value,
+ "Wrong argument for STRING_WITH_LEN()");
+ return s;
+}
+#define STRING_WITH_LEN(X) _swl_check<decltype(X)>(X), ((size_t) (sizeof(X) - 1))
+#else
+#define STRING_WITH_LEN(X) (X ""), ((size_t) (sizeof(X) - 1))
+#endif
+
+#define USTRING_WITH_LEN(X) (uchar*) STRING_WITH_LEN(X)
+#define C_STRING_WITH_LEN(X) (char *) STRING_WITH_LEN(X)
#define LEX_STRING_WITH_LEN(X) (X).str, (X).length
typedef struct st_mysql_const_lex_string LEX_CSTRING;