From: Christopher Dykes Date: Wed, 26 Apr 2017 00:14:26 +0000 (-0700) Subject: Delete the non-char integeral forms of fbstring::operator= X-Git-Tag: v2017.05.01.00~12 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ce97926001344be626e092d24b6c977447d8c4a8;p=folly.git Delete the non-char integeral forms of fbstring::operator= Summary: They allow for assignments that make no sense, so make it impossible to do so. Reviewed By: yfeldblum Differential Revision: D4919606 fbshipit-source-id: 24d8e036eff33a8c6def4672c0d098f0edd5c5b3 --- diff --git a/folly/FBString.h b/folly/FBString.h index 91b1ab68..45710dc7 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -1230,7 +1230,15 @@ public: return assign(s); } - basic_fbstring& operator=(value_type c); + // This actually goes directly against the C++ spec, but the + // value_type overload is dangerous, so we're explicitly deleting + // any overloads of operator= that could implicitly convert to + // value_type. + template + typename std::enable_if< + std::is_same::type, value_type>::value, + basic_fbstring&>::type + operator=(TP c); basic_fbstring& operator=(std::initializer_list il) { return assign(il.begin(), il.end()); @@ -1860,8 +1868,13 @@ inline basic_fbstring& basic_fbstring::operator=( } template -inline basic_fbstring& basic_fbstring::operator=( - const value_type c) { +template +inline typename std::enable_if< + std::is_same< + typename std::decay::type, + typename basic_fbstring::value_type>::value, + basic_fbstring&>::type +basic_fbstring::operator=(TP c) { Invariant checker(*this); if (empty()) { diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index 2c867dd1..c2110d1f 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -208,7 +208,8 @@ template void clause11_21_4_2_lprime(String & test) { } template void clause11_21_4_2_m(String & test) { // Assignment from char - test = random('a', 'z'); + using value_type = typename String::value_type; + test = random(static_cast('a'), static_cast('z')); } template void clause11_21_4_2_n(String & test) { // Assignment from initializer_list