From ba88b3f6f91ee79817eab51bfd5694dba9244636 Mon Sep 17 00:00:00 2001 From: Nicholas Ormrod Date: Thu, 30 Oct 2014 13:55:13 -0700 Subject: [PATCH] Make dynamic noexcept Summary: Many dynamic operations, including its move constructor, are noexcept but not labeled so. Labeled some important functions as noexcept. Test Plan: run unit tests Reviewed By: delong.j@fb.com Subscribers: tudorb, philipp, sdwilsh, njormrod, folly-diffs@ FB internal diff: D1644380 Tasks: 5486739 Signature: t1:1644380:1414618757:fb910d8a3fe3e634da4215c432577edf7371be61 --- folly/dynamic-inl.h | 30 +++++++++++++++--------------- folly/dynamic.h | 16 ++++++++-------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index d4550a2c..81f063fb 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -309,13 +309,13 @@ inline dynamic::dynamic(dynamic const& o) *this = o; } -inline dynamic::dynamic(dynamic&& o) +inline dynamic::dynamic(dynamic&& o) noexcept : type_(NULLT) { *this = std::move(o); } -inline dynamic::~dynamic() { destroy(); } +inline dynamic::~dynamic() noexcept { destroy(); } template dynamic::dynamic(T t) { @@ -508,7 +508,7 @@ inline dynamic& dynamic::operator=(dynamic const& o) { return *this; } -inline dynamic& dynamic::operator=(dynamic&& o) { +inline dynamic& dynamic::operator=(dynamic&& o) noexcept { if (&o != this) { destroy(); #define FB_X(T) new (getAddress()) T(std::move(*o.getAddress())) @@ -772,7 +772,7 @@ T dynamic::asImpl() const { // Return a T* to our type, or null if we're not that type. template -T* dynamic::get_nothrow() { +T* dynamic::get_nothrow() noexcept { if (type_ != TypeInfo::type) { return nullptr; } @@ -780,40 +780,40 @@ T* dynamic::get_nothrow() { } template -T const* dynamic::get_nothrow() const { +T const* dynamic::get_nothrow() const noexcept { return const_cast(this)->get_nothrow(); } // Return T* for where we can put a T, without type checking. (Memory // might be uninitialized, even.) template -T* dynamic::getAddress() { +T* dynamic::getAddress() noexcept { return GetAddrImpl::get(u_); } template -T const* dynamic::getAddress() const { +T const* dynamic::getAddress() const noexcept { return const_cast(this)->getAddress(); } template struct dynamic::GetAddrImpl {}; template<> struct dynamic::GetAddrImpl { - static void** get(Data& d) { return &d.nul; } + static void** get(Data& d) noexcept { return &d.nul; } }; template<> struct dynamic::GetAddrImpl { - static Array* get(Data& d) { return &d.array; } + static Array* get(Data& d) noexcept { return &d.array; } }; template<> struct dynamic::GetAddrImpl { - static bool* get(Data& d) { return &d.boolean; } + static bool* get(Data& d) noexcept { return &d.boolean; } }; template<> struct dynamic::GetAddrImpl { - static int64_t* get(Data& d) { return &d.integer; } + static int64_t* get(Data& d) noexcept { return &d.integer; } }; template<> struct dynamic::GetAddrImpl { - static double* get(Data& d) { return &d.doubl; } + static double* get(Data& d) noexcept { return &d.doubl; } }; template<> struct dynamic::GetAddrImpl { - static fbstring* get(Data& d) { return &d.string; } + static fbstring* get(Data& d) noexcept { return &d.string; } }; template<> struct dynamic::GetAddrImpl { static_assert(sizeof(ObjectImpl) <= sizeof(Data::objectBuffer), @@ -821,7 +821,7 @@ template<> struct dynamic::GetAddrImpl { " amount of space depending on its template parameters. This is " "weird. Make objectBuffer bigger if you want to compile dynamic."); - static ObjectImpl* get(Data& d) { + static ObjectImpl* get(Data& d) noexcept { void* data = &d.objectBuffer; return static_cast(data); } @@ -846,7 +846,7 @@ inline char const* dynamic::typeName(Type t) { #undef FB_X } -inline void dynamic::destroy() { +inline void dynamic::destroy() noexcept { // This short-circuit speeds up some microbenchmarks. if (type_ == NULLT) return; diff --git a/folly/dynamic.h b/folly/dynamic.h index ecdcdaf1..906059ca 100644 --- a/folly/dynamic.h +++ b/folly/dynamic.h @@ -180,8 +180,8 @@ public: template dynamic(Iterator first, Iterator last); dynamic(dynamic const&); - dynamic(dynamic&&); - ~dynamic(); + dynamic(dynamic&&) noexcept; + ~dynamic() noexcept; /* * "Deep" equality comparison. This will compare all the way down @@ -223,7 +223,7 @@ public: * Basic guarantee only. */ dynamic& operator=(dynamic const&); - dynamic& operator=(dynamic&&); + dynamic& operator=(dynamic&&) noexcept; /* * For simple dynamics (not arrays or objects), this prints the @@ -494,15 +494,15 @@ private: template T const& get() const; template T& get(); - template T* get_nothrow(); - template T const* get_nothrow() const; - template T* getAddress(); - template T const* getAddress() const; + template T* get_nothrow() noexcept; + template T const* get_nothrow() const noexcept; + template T* getAddress() noexcept; + template T const* getAddress() const noexcept; template T asImpl() const; static char const* typeName(Type); - void destroy(); + void destroy() noexcept; void print(std::ostream&) const; void print_as_pseudo_json(std::ostream&) const; // see json.cpp -- 2.34.1