#include <algorithm>
#include <cassert>
#include <new>
-#include <cstring>
#include <utility>
namespace llvm {
}
};
+#if !defined(__GNUC__) || defined(__clang__) // GCC up to GCC7 miscompiles this.
/// Storage for trivially copyable types only.
template <typename T> struct OptionalStorage<T, true> {
AlignedCharArrayUnion<T> storage;
OptionalStorage() = default;
- OptionalStorage(const T &y) : hasVal(true) {
- // We use memmove here because we know that T is trivially copyable and GCC
- // up to 7 miscompiles placement new.
- std::memmove(storage.buffer, &y, sizeof(y));
- }
+ OptionalStorage(const T &y) : hasVal(true) { new (storage.buffer) T(y); }
OptionalStorage &operator=(const T &y) {
+ *reinterpret_cast<T *>(storage.buffer) = y;
hasVal = true;
- // We use memmove here because we know that T is trivially copyable and GCC
- // up to 7 miscompiles placement new.
- std::memmove(storage.buffer, &y, sizeof(y));
return *this;
}
void reset() { hasVal = false; }
};
+#endif
} // namespace optional_detail
template <typename T> class Optional {
CheckRelation<GreaterEqual>(InequalityLhs, InequalityRhs, !IsLess);
}
-#if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \
- (defined(__GNUC__) && __GNUC__ >= 5)
+#if __has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)
static_assert(std::is_trivially_copyable<Optional<int>>::value,
"Should be trivially copyable");
static_assert(