Address GCC compilation issues
invalid suffix on literal no return statement in function returning non-void CuckooStep::operator= extra qualification ‘rocksdb::spatial::Variant:: dereferencing type-punned pointer will break strict-aliasing rules
This commit is contained in:
parent
19e13a595d
commit
ca2fe2c1b6
@ -57,13 +57,13 @@ struct Variant {
|
|||||||
new (&data_.s) std::string(s);
|
new (&data_.s) std::string(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Variant& v) : type_(v.type_) {
|
Variant(const Variant& v) : type_(v.type_) {
|
||||||
Init(v, data_);
|
Init(v, data_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant& operator=(const Variant& v);
|
Variant& operator=(const Variant& v);
|
||||||
|
|
||||||
Variant::Variant(Variant&& rhs) : type_(kNull) {
|
Variant(Variant&& rhs) : type_(kNull) {
|
||||||
*this = std::move(rhs);
|
*this = std::move(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ struct Variant {
|
|||||||
bool get_bool() const { return data_.b; }
|
bool get_bool() const { return data_.b; }
|
||||||
uint64_t get_int() const { return data_.i; }
|
uint64_t get_int() const { return data_.i; }
|
||||||
double get_double() const { return data_.d; }
|
double get_double() const { return data_.d; }
|
||||||
const std::string& get_string() const { return *reinterpret_cast<const std::string*>(&data_.s); }
|
const std::string& get_string() const { return *GetStringPtr(data_); }
|
||||||
|
|
||||||
bool operator==(const Variant& other) const;
|
bool operator==(const Variant& other) const;
|
||||||
bool operator!=(const Variant& rhs) const { return !(*this == rhs); }
|
bool operator!=(const Variant& rhs) const { return !(*this == rhs); }
|
||||||
@ -95,12 +95,23 @@ struct Variant {
|
|||||||
char s[sizeof(std::string)];
|
char s[sizeof(std::string)];
|
||||||
} data_;
|
} data_;
|
||||||
|
|
||||||
|
// Avoid type_punned aliasing problem
|
||||||
|
static std::string* GetStringPtr(Data& d) {
|
||||||
|
void* p = d.s;
|
||||||
|
return reinterpret_cast<std::string*>(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const std::string* GetStringPtr(const Data& d) {
|
||||||
|
const void* p = d.s;
|
||||||
|
return reinterpret_cast<const std::string*>(p);
|
||||||
|
}
|
||||||
|
|
||||||
static void Init(const Variant&, Data&);
|
static void Init(const Variant&, Data&);
|
||||||
|
|
||||||
static void Destroy(Type t, Data& d) {
|
static void Destroy(Type t, Data& d) {
|
||||||
if (t == kString) {
|
if (t == kString) {
|
||||||
using std::string;
|
using std::string;
|
||||||
reinterpret_cast<std::string*>(&d.s)->~string();
|
GetStringPtr(d)->~string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -50,6 +50,7 @@ struct CuckooStep {
|
|||||||
bucket_id_ = std::move(rhs.bucket_id_);
|
bucket_id_ = std::move(rhs.bucket_id_);
|
||||||
prev_step_id_ = std::move(rhs.prev_step_id_);
|
prev_step_id_ = std::move(rhs.prev_step_id_);
|
||||||
depth_ = std::move(rhs.depth_);
|
depth_ = std::move(rhs.depth_);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CuckooStep(const CuckooStep&) = delete;
|
CuckooStep(const CuckooStep&) = delete;
|
||||||
|
@ -347,7 +347,7 @@ void DBOptions::Dump(Logger* log) const {
|
|||||||
stats_dump_period_sec);
|
stats_dump_period_sec);
|
||||||
Warn(log, " Options.advise_random_on_open: %d",
|
Warn(log, " Options.advise_random_on_open: %d",
|
||||||
advise_random_on_open);
|
advise_random_on_open);
|
||||||
Warn(log, " Options.db_write_buffer_size: %"ROCKSDB_PRIszt"d",
|
Warn(log, " Options.db_write_buffer_size: %" ROCKSDB_PRIszt "d",
|
||||||
db_write_buffer_size);
|
db_write_buffer_size);
|
||||||
Warn(log, " Options.access_hint_on_compaction_start: %s",
|
Warn(log, " Options.access_hint_on_compaction_start: %s",
|
||||||
access_hints[access_hint_on_compaction_start]);
|
access_hints[access_hint_on_compaction_start]);
|
||||||
@ -430,7 +430,7 @@ void ColumnFamilyOptions::Dump(Logger* log) const {
|
|||||||
max_bytes_for_level_multiplier);
|
max_bytes_for_level_multiplier);
|
||||||
for (size_t i = 0; i < max_bytes_for_level_multiplier_additional.size();
|
for (size_t i = 0; i < max_bytes_for_level_multiplier_additional.size();
|
||||||
i++) {
|
i++) {
|
||||||
Warn(log, "Options.max_bytes_for_level_multiplier_addtl[%"ROCKSDB_PRIszt"]: %d", i,
|
Warn(log, "Options.max_bytes_for_level_multiplier_addtl[%" ROCKSDB_PRIszt "]: %d", i,
|
||||||
max_bytes_for_level_multiplier_additional[i]);
|
max_bytes_for_level_multiplier_additional[i]);
|
||||||
}
|
}
|
||||||
Warn(log, " Options.max_sequential_skip_in_iterations: %" PRIu64,
|
Warn(log, " Options.max_sequential_skip_in_iterations: %" PRIu64,
|
||||||
|
@ -79,7 +79,7 @@ void Variant::Init(const Variant& v, Data& d) {
|
|||||||
d.d = v.data_.d;
|
d.d = v.data_.d;
|
||||||
break;
|
break;
|
||||||
case kString:
|
case kString:
|
||||||
new (d.s) std::string(*reinterpret_cast<const std::string*>(v.data_.s));
|
new (d.s) std::string(*GetStringPtr(v.data_));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
@ -107,7 +107,7 @@ Variant& Variant::operator=(Variant&& rhs) {
|
|||||||
|
|
||||||
Destroy(type_, data_);
|
Destroy(type_, data_);
|
||||||
if (rhs.type_ == kString) {
|
if (rhs.type_ == kString) {
|
||||||
new (data_.s) std::string(std::move(*reinterpret_cast<std::string*>(rhs.data_.s)));
|
new (data_.s) std::string(std::move(*GetStringPtr(rhs.data_)));
|
||||||
} else {
|
} else {
|
||||||
data_ = rhs.data_;
|
data_ = rhs.data_;
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ bool Variant::operator==(const Variant& rhs) const {
|
|||||||
case kDouble:
|
case kDouble:
|
||||||
return data_.d == rhs.data_.d;
|
return data_.d == rhs.data_.d;
|
||||||
case kString:
|
case kString:
|
||||||
return *reinterpret_cast<const std::string*>(data_.s) == *reinterpret_cast<const std::string*>(rhs.data_.s);
|
return *GetStringPtr(data_) == *GetStringPtr(rhs.data_);
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user