*/
template <class Char> class fbstring_core {
public:
- fbstring_core() {
+ fbstring_core() noexcept {
// Only initialize the tag, will set the MSBs (i.e. the small
// string size) to zero too
ml_.capacity_ = maxSmallSize << (8 * (sizeof(size_t) - sizeof(Char)));
assert(memcmp(data(), rhs.data(), size() * sizeof(Char)) == 0);
}
- fbstring_core(fbstring_core&& goner) {
+ fbstring_core(fbstring_core&& goner) noexcept {
if (goner.category() == isSmall) {
// Just copy, leave the goner in peace
new(this) fbstring_core(goner.small_, goner.smallSize());
assert(memcmp(this->data(), data, size * sizeof(Char)) == 0);
}
- ~fbstring_core() {
+ ~fbstring_core() noexcept {
auto const c = category();
if (c == isSmall) {
return;
public:
// C++11 21.4.2 construct/copy/destroy
- explicit basic_fbstring(const A& a = A()) {
+ explicit basic_fbstring(const A& a = A()) noexcept {
}
basic_fbstring(const basic_fbstring& str)
}
// Move constructor
- basic_fbstring(basic_fbstring&& goner) : store_(std::move(goner.store_)) {
+ basic_fbstring(basic_fbstring&& goner) noexcept
+ : store_(std::move(goner.store_)) {
}
#ifndef _LIBSTDCXX_FBSTRING
assign(il.begin(), il.end());
}
- ~basic_fbstring() {
+ ~basic_fbstring() noexcept {
}
basic_fbstring& operator=(const basic_fbstring& lhs) {
}
// Move assignment
- basic_fbstring& operator=(basic_fbstring&& goner) {
+ basic_fbstring& operator=(basic_fbstring&& goner) noexcept {
if (FBSTRING_UNLIKELY(&goner == this)) {
// Compatibility with std::basic_string<>,
// C++11 21.4.2 [string.cons] / 23 requires self-move-assignment support.
#include <gflags/gflags.h>
#include "folly/Foreach.h"
+#include "folly/Portability.h"
#include "folly/Random.h"
#include "folly/Conv.h"
EXPECT_EQ(str, "HellO");
}
+TEST(FBString, noexcept) {
+ EXPECT_TRUE(noexcept(fbstring()));
+ // std::move is not marked noexcept in gcc 4.6, sigh
+#if __GNUC_PREREQ(4, 7)
+ fbstring x;
+ EXPECT_FALSE(noexcept(fbstring(x)));
+ EXPECT_TRUE(noexcept(fbstring(std::move(x))));
+ fbstring y;
+ EXPECT_FALSE(noexcept(y = x));
+ EXPECT_TRUE(noexcept(y = std::move(x)));
+#endif
+}
+
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true);