Commit 31ef7c2d authored by Kenton Varda's avatar Kenton Varda

Fix GCC.

parent ec49e07a
...@@ -149,10 +149,11 @@ BUILT_SOURCES = $(test_capnpc_outputs) $(capnpc_outputs) ...@@ -149,10 +149,11 @@ BUILT_SOURCES = $(test_capnpc_outputs) $(capnpc_outputs)
check_PROGRAMS = capnproto-test check_PROGRAMS = capnproto-test
capnproto_test_LDADD = -lgtest -lgtest_main libcapnproto.a capnproto_test_LDADD = -lgtest -lgtest_main libcapnproto.a
capnproto_test_SOURCES = \ capnproto_test_SOURCES = \
src/kj/array-test.c++ \
src/kj/common-test.c++ \ src/kj/common-test.c++ \
src/kj/debug-test.c++ \ src/kj/memory-test.c++ \
src/kj/array-test.c++ \
src/kj/string-test.c++ \ src/kj/string-test.c++ \
src/kj/debug-test.c++ \
src/kj/units-test.c++ \ src/kj/units-test.c++ \
src/capnproto/blob-test.c++ \ src/capnproto/blob-test.c++ \
src/capnproto/layout-test.c++ \ src/capnproto/layout-test.c++ \
......
...@@ -101,13 +101,15 @@ TEST(Array, TrivialConstructor) { ...@@ -101,13 +101,15 @@ TEST(Array, TrivialConstructor) {
{ {
Array<char> chars = heapArray<char>(32); Array<char> chars = heapArray<char>(32);
// Somewhat hacky: We can't guarantee that the new array is allocated in the same place, but // TODO(test): The following doesn't work in opt mode -- I guess some allocators zero the
// any reasonable allocator is highly likely to do so. If it does, then we expect that the // memory? Is there some other way we can test this? Maybe override malloc()?
// memory has not been initialized. // // Somewhat hacky: We can't guarantee that the new array is allocated in the same place, but
if (chars.begin() == ptr) { // // any reasonable allocator is highly likely to do so. If it does, then we expect that the
EXPECT_NE(chars[0], 0); // // memory has not been initialized.
EXPECT_NE(chars[1], 0); // if (chars.begin() == ptr) {
} // EXPECT_NE(chars[0], 0);
// EXPECT_NE(chars[1], 0);
// }
} }
} }
......
...@@ -77,8 +77,7 @@ public: ...@@ -77,8 +77,7 @@ public:
other.ptr = nullptr; other.ptr = nullptr;
other.size_ = 0; other.size_ = 0;
} }
template <typename = EnableIfConst<T>> inline Array(Array<RemoveConstOrBogus<T>>&& other) noexcept
inline Array(Array<RemoveConst<T>>&& other) noexcept
: ptr(other.ptr), size_(other.size_), disposer(other.disposer) { : ptr(other.ptr), size_(other.size_), disposer(other.disposer) {
other.ptr = nullptr; other.ptr = nullptr;
other.size_ = 0; other.size_ = 0;
......
...@@ -158,6 +158,13 @@ TEST(Common, MaybeConstness) { ...@@ -158,6 +158,13 @@ TEST(Common, MaybeConstness) {
Maybe<int&> mi = i; Maybe<int&> mi = i;
const Maybe<int&> cmi = mi; const Maybe<int&> cmi = mi;
// const Maybe<int&> cmi2 = cmi; // shouldn't compile! Transitive const violation. // const Maybe<int&> cmi2 = cmi; // shouldn't compile! Transitive const violation.
KJ_IF_MAYBE(i2, cmi) {
EXPECT_EQ(&i, i2);
} else {
ADD_FAILURE();
}
Maybe<const int&> mci = mi; Maybe<const int&> mci = mi;
const Maybe<const int&> cmci = mci; const Maybe<const int&> cmci = mci;
const Maybe<const int&> cmci2 = cmci; const Maybe<const int&> cmci2 = cmci;
......
...@@ -243,6 +243,10 @@ template <typename T> struct EnableIfConst_; ...@@ -243,6 +243,10 @@ template <typename T> struct EnableIfConst_;
template <typename T> struct EnableIfConst_<const T> { typedef T Type; }; template <typename T> struct EnableIfConst_<const T> { typedef T Type; };
template <typename T> using EnableIfConst = typename EnableIfConst_<T>::Type; template <typename T> using EnableIfConst = typename EnableIfConst_<T>::Type;
template <typename T> struct RemoveConstOrBogus_ { struct Type; };
template <typename T> struct RemoveConstOrBogus_<const T> { typedef T Type; };
template <typename T> using RemoveConstOrBogus = typename RemoveConstOrBogus_<T>::Type;
// ======================================================================================= // =======================================================================================
// Equivalents to std::move() and std::forward(), since these are very commonly needed and the // Equivalents to std::move() and std::forward(), since these are very commonly needed and the
// std header <utility> pulls in lots of other stuff. // std header <utility> pulls in lots of other stuff.
......
...@@ -88,8 +88,7 @@ public: ...@@ -88,8 +88,7 @@ public:
Own(const Own& other) = delete; Own(const Own& other) = delete;
inline Own(Own&& other) noexcept inline Own(Own&& other) noexcept
: disposer(other.disposer), ptr(other.ptr) { other.ptr = nullptr; } : disposer(other.disposer), ptr(other.ptr) { other.ptr = nullptr; }
template <typename = EnableIfConst<T>> inline Own(Own<RemoveConstOrBogus<T>>&& other) noexcept
inline Own(Own<RemoveConst<T>>&& other) noexcept
: disposer(other.disposer), ptr(other.ptr) { other.ptr = nullptr; } : disposer(other.disposer), ptr(other.ptr) { other.ptr = nullptr; }
template <typename U> template <typename U>
inline Own(Own<U>&& other) noexcept inline Own(Own<U>&& other) noexcept
......
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