From c4e871ea2de6cc5c8086854084aec35ec2c9f058 Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Mon, 4 Jul 2016 17:44:22 +0300 Subject: [PATCH] Work around unexpected data_value constructor If someone tried to naively use utf8_type->decompose("18wX"), this would mysteriously fail, returning an empty key. decompose takes a data_value, so the compiler looked for an implict conversion from the string constant (const char*) to data_value. We did not have such a conversion, only conversion from sstring. But the compiler chose (backed by the C++ standard, no doubt) to implicitly convert the const char* to a bool (!), and then use data_value(bool). It did not convert the const char* to an sstring, nor did it warn about the possible ambiguity. So this patch adds a data_value(const char*) constructor, so people will not fall into the same trap that I fell into... Signed-off-by: Nadav Har'El Message-Id: <1467643462-6349-1-git-send-email-nyh@scylladb.com> --- types.cc | 3 +++ types.hh | 1 + 2 files changed, 4 insertions(+) diff --git a/types.cc b/types.cc index 5f24e52e56..4e8123d037 100644 --- a/types.cc +++ b/types.cc @@ -2885,6 +2885,9 @@ data_value::data_value(bytes v) : data_value(make_new(bytes_type, v)) { data_value::data_value(sstring v) : data_value(make_new(utf8_type, v)) { } +data_value::data_value(const char* v) : data_value(make_new(utf8_type, sstring(v))) { +} + data_value::data_value(bool v) : data_value(make_new(boolean_type, v)) { } diff --git a/types.hh b/types.hh index acfbd635ca..04f11b5d66 100644 --- a/types.hh +++ b/types.hh @@ -308,6 +308,7 @@ public: // note: somewhat dangerous, consider a factory function instead explicit data_value(bytes); data_value(sstring); + data_value(const char*); data_value(bool); data_value(int32_t); data_value(int64_t);