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

Reland "Applied noexcept to all mctors and massigns"

This is a reland of baa055c7

Original change's description:
> 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/1152817
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Reviewed-by: Marja Hölttä <marja@chromium.org>
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Commit-Queue: Florian Sattler <sattlerf@google.com>
> Cr-Commit-Position: refs/heads/master@{#54841}

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