Commit baa055c7 authored by Florian Sattler's avatar Florian Sattler Committed by Commit Bot

Applied noexcept to all mctors and massigns

Refactoring the code base to use noexcept for their move constructors and move
assignment operators.

Bug: v8:7999

Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I13d24eddba3bfa601cff26fd680a040cf4e71426
Reviewed-on: https://chromium-review.googlesource.com/1152817Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Florian Sattler <sattlerf@google.com>
Cr-Commit-Position: refs/heads/master@{#54841}
parent e4f595c2
......@@ -92,4 +92,12 @@
#endif // V8_CC_MSVC
// Allowing the use of noexcept by removing the keyword on older compilers that
// do not support adding noexcept to default members.
#if (V8_GNUC_PREREQ(4, 9, 0)) || (defined(__clang__) && __cplusplus > 201300L)
#define V8_NOEXCEPT noexcept
#else
#define V8_NOEXCEPT
#endif
#endif // V8_BASE_COMPILER_SPECIFIC_H_
......@@ -134,9 +134,9 @@ V8_INLINE Dest bit_cast(Source const& source) {
// Disallow copying a type, and only provide move construction and move
// assignment. Especially useful for move-only structs.
#define MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(TypeName) \
TypeName(TypeName&&) = default; \
TypeName& operator=(TypeName&&) = default; \
#define MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(TypeName) \
TypeName(TypeName&&) V8_NOEXCEPT = default; \
TypeName& operator=(TypeName&&) V8_NOEXCEPT = default; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// A macro to disallow the dynamic allocation.
......
......@@ -131,7 +131,7 @@ class Optional {
if (!other.storage_.is_null_) Init(other.value());
}
Optional(Optional&& other) {
Optional(Optional&& other) V8_NOEXCEPT {
if (!other.storage_.is_null_) Init(std::move(other.value()));
}
......@@ -164,7 +164,7 @@ class Optional {
return *this;
}
Optional& operator=(Optional&& other) {
Optional& operator=(Optional&& other) V8_NOEXCEPT {
if (other.storage_.is_null_) {
FreeIfNeeded();
return *this;
......
......@@ -139,13 +139,15 @@ class ExternalizedContents {
: base_(contents.AllocationBase()),
length_(contents.AllocationLength()),
mode_(contents.AllocationMode()) {}
ExternalizedContents(ExternalizedContents&& other)
: base_(other.base_), length_(other.length_), mode_(other.mode_) {
ExternalizedContents(ExternalizedContents&& other) V8_NOEXCEPT
: base_(other.base_),
length_(other.length_),
mode_(other.mode_) {
other.base_ = nullptr;
other.length_ = 0;
other.mode_ = ArrayBuffer::Allocator::AllocationMode::kNormal;
}
ExternalizedContents& operator=(ExternalizedContents&& other) {
ExternalizedContents& operator=(ExternalizedContents&& other) V8_NOEXCEPT {
if (this != &other) {
base_ = other.base_;
length_ = other.length_;
......
......@@ -2,6 +2,7 @@ include_rules = [
"-src",
"-include/v8-debug.h",
"+src/base/atomicops.h",
"+src/base/compiler-specific.h",
"+src/base/macros.h",
"+src/base/logging.h",
"+src/base/platform/platform.h",
......
......@@ -375,8 +375,9 @@ String16::String16() {}
String16::String16(const String16& other)
: m_impl(other.m_impl), hash_code(other.hash_code) {}
String16::String16(String16&& other)
: m_impl(std::move(other.m_impl)), hash_code(other.hash_code) {}
String16::String16(String16&& other) V8_NOEXCEPT
: m_impl(std::move(other.m_impl)),
hash_code(other.hash_code) {}
String16::String16(const UChar* characters, size_t size)
: m_impl(characters, size) {}
......@@ -399,7 +400,7 @@ String16& String16::operator=(const String16& other) {
return *this;
}
String16& String16::operator=(String16&& other) {
String16& String16::operator=(String16&& other) V8_NOEXCEPT {
m_impl = std::move(other.m_impl);
hash_code = other.hash_code;
return *this;
......
......@@ -12,6 +12,8 @@
#include <string>
#include <vector>
#include "src/base/compiler-specific.h"
namespace v8_inspector {
using UChar = uint16_t;
......@@ -22,7 +24,7 @@ class String16 {
String16();
String16(const String16& other);
String16(String16&& other);
String16(String16&& other) V8_NOEXCEPT;
String16(const UChar* characters, size_t size);
String16(const UChar* characters); // NOLINT(runtime/explicit)
String16(const char* characters); // NOLINT(runtime/explicit)
......@@ -30,7 +32,7 @@ class String16 {
explicit String16(const std::basic_string<UChar>& impl);
String16& operator=(const String16& other);
String16& operator=(String16&& other);
String16& operator=(String16&& other) V8_NOEXCEPT;
static String16 fromInteger(int);
static String16 fromInteger(size_t);
......
......@@ -300,8 +300,10 @@ class SerializedData {
SerializedData(byte* data, int size)
: data_(data), size_(size), owns_data_(false) {}
SerializedData() : data_(nullptr), size_(0), owns_data_(false) {}
SerializedData(SerializedData&& other)
: data_(other.data_), size_(other.size_), owns_data_(other.owns_data_) {
SerializedData(SerializedData&& other) V8_NOEXCEPT
: data_(other.data_),
size_(other.size_),
owns_data_(other.owns_data_) {
// Ensure |other| will not attempt to destroy our data in destructor.
other.owns_data_ = false;
}
......
......@@ -145,7 +145,7 @@ void ErrorThrower::Reset() {
error_msg_.clear();
}
ErrorThrower::ErrorThrower(ErrorThrower&& other)
ErrorThrower::ErrorThrower(ErrorThrower&& other) V8_NOEXCEPT
: isolate_(other.isolate_),
context_(other.context_),
error_type_(other.error_type_),
......
......@@ -26,10 +26,10 @@ class V8_EXPORT_PRIVATE ResultBase {
protected:
ResultBase() = default;
ResultBase& operator=(ResultBase&& other) = default;
ResultBase& operator=(ResultBase&& other) V8_NOEXCEPT = default;
public:
ResultBase(ResultBase&& other)
ResultBase(ResultBase&& other) V8_NOEXCEPT
: error_offset_(other.error_offset_),
error_msg_(std::move(other.error_msg_)) {}
......@@ -73,10 +73,10 @@ class Result : public ResultBase {
explicit Result(S&& value) : val(std::forward<S>(value)) {}
template <typename S>
Result(Result<S>&& other)
: ResultBase(std::move(other)), val(std::move(other.val)) {}
Result(Result<S>&& other) V8_NOEXCEPT : ResultBase(std::move(other)),
val(std::move(other.val)) {}
Result& operator=(Result&& other) = default;
Result& operator=(Result&& other) V8_NOEXCEPT = default;
static Result<T> PRINTF_FORMAT(1, 2) Error(const char* format, ...) {
va_list args;
......@@ -99,7 +99,7 @@ class V8_EXPORT_PRIVATE ErrorThrower {
ErrorThrower(Isolate* isolate, const char* context)
: isolate_(isolate), context_(context) {}
// Explicitly allow move-construction. Disallow copy (below).
ErrorThrower(ErrorThrower&& other);
ErrorThrower(ErrorThrower&& other) V8_NOEXCEPT;
~ErrorThrower();
PRINTF_FORMAT(2, 3) void TypeError(const char* fmt, ...);
......
......@@ -21,7 +21,7 @@ const char src_simple[] = "function foo() { var x = 2 * a() + b; }";
struct ScannerTestHelper {
ScannerTestHelper() = default;
ScannerTestHelper(ScannerTestHelper&& other)
ScannerTestHelper(ScannerTestHelper&& other) V8_NOEXCEPT
: unicode_cache(std::move(other.unicode_cache)),
stream(std::move(other.stream)),
scanner(std::move(other.scanner)) {}
......
......@@ -43,8 +43,10 @@ class DataRange {
// lead to OOM because the end might not be reached.
// Define move constructor and move assignment, disallow copy constructor and
// copy assignment (below).
DataRange(DataRange&& other) : DataRange(other.data_) { other.data_ = {}; }
DataRange& operator=(DataRange&& other) {
DataRange(DataRange&& other) V8_NOEXCEPT : DataRange(other.data_) {
other.data_ = {};
}
DataRange& operator=(DataRange&& other) V8_NOEXCEPT {
data_ = other.data_;
other.data_ = {};
return *this;
......
......@@ -63,12 +63,12 @@ class AsmTypeTest : public TestWithZone {
class FunctionTypeBuilder {
public:
FunctionTypeBuilder(FunctionTypeBuilder&& b)
FunctionTypeBuilder(FunctionTypeBuilder&& b) V8_NOEXCEPT
: function_type_(b.function_type_) {
b.function_type_ = nullptr;
}
FunctionTypeBuilder& operator=(FunctionTypeBuilder&& b) {
FunctionTypeBuilder& operator=(FunctionTypeBuilder&& b) V8_NOEXCEPT {
if (this != &b) {
function_type_ = b.function_type_;
b.function_type_ = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment