From 5e67443a1abe2840774b22e1de212063cccd0738 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 15 Jan 2021 15:26:03 +0100 Subject: [PATCH] util/{Const,Writable}Buffer: always enable assertions --- src/util/ConstBuffer.hxx | 23 +---------------------- src/util/WritableBuffer.hxx | 24 ++---------------------- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx index 9a3487341..949420871 100644 --- a/src/util/ConstBuffer.hxx +++ b/src/util/ConstBuffer.hxx @@ -32,11 +32,8 @@ #include "Compiler.h" -#include - -#ifndef NDEBUG #include -#endif +#include template struct ConstBuffer; @@ -139,9 +136,7 @@ struct ConstBuffer { */ constexpr static ConstBuffer FromVoid(ConstBuffer other) noexcept { static_assert(sizeof(T) > 0, "Empty base type"); -#ifndef NDEBUG assert(other.size % sizeof(T) == 0); -#endif return FromVoidFloor(other); } @@ -192,9 +187,7 @@ struct ConstBuffer { } constexpr reference operator[](size_type i) const noexcept { -#ifndef NDEBUG assert(i < size); -#endif return data[i]; } @@ -204,9 +197,7 @@ struct ConstBuffer { * be empty. */ constexpr reference front() const noexcept { -#ifndef NDEBUG assert(!empty()); -#endif return data[0]; } @@ -215,9 +206,7 @@ struct ConstBuffer { * be empty. */ constexpr reference back() const noexcept { -#ifndef NDEBUG assert(!empty()); -#endif return data[size - 1]; } @@ -226,9 +215,7 @@ struct ConstBuffer { * not actually modify the buffer). Buffer must not be empty. */ constexpr void pop_front() noexcept { -#ifndef NDEBUG assert(!empty()); -#endif ++data; --size; @@ -239,9 +226,7 @@ struct ConstBuffer { * not actually modify the buffer). Buffer must not be empty. */ constexpr void pop_back() noexcept { -#ifndef NDEBUG assert(!empty()); -#endif --size; } @@ -257,9 +242,7 @@ struct ConstBuffer { } constexpr void skip_front(size_type n) noexcept { -#ifndef NDEBUG assert(size >= n); -#endif data += n; size -= n; @@ -270,10 +253,8 @@ struct ConstBuffer { * size attribute to retain the old end address. */ void MoveFront(pointer new_data) noexcept { -#ifndef NDEBUG assert(IsNull() == (new_data == nullptr)); assert(new_data <= end()); -#endif size = end() - new_data; data = new_data; @@ -284,10 +265,8 @@ struct ConstBuffer { * size). */ void SetEnd(pointer new_end) noexcept { -#ifndef NDEBUG assert(IsNull() == (new_end == nullptr)); assert(new_end >= begin()); -#endif size = new_end - data; } diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index 1b92a3850..0b82c9146 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -33,11 +33,8 @@ #include "ConstBuffer.hxx" #include "Compiler.h" -#include - -#ifndef NDEBUG #include -#endif +#include template struct WritableBuffer; @@ -140,14 +137,9 @@ struct WritableBuffer { * the assertion below ensures that the size is a multiple of * sizeof(T). */ -#ifdef NDEBUG - constexpr -#endif - static WritableBuffer FromVoid(WritableBuffer other) noexcept { + static constexpr WritableBuffer FromVoid(WritableBuffer other) noexcept { static_assert(sizeof(T) > 0, "Empty base type"); -#ifndef NDEBUG assert(other.size % sizeof(T) == 0); -#endif return FromVoidFloor(other); } @@ -189,9 +181,7 @@ struct WritableBuffer { } constexpr reference operator[](size_type i) const noexcept { -#ifndef NDEBUG assert(i < size); -#endif return data[i]; } @@ -201,9 +191,7 @@ struct WritableBuffer { * be empty. */ constexpr reference front() const noexcept { -#ifndef NDEBUG assert(!empty()); -#endif return data[0]; } @@ -212,9 +200,7 @@ struct WritableBuffer { * be empty. */ constexpr reference back() const noexcept { -#ifndef NDEBUG assert(!empty()); -#endif return data[size - 1]; } @@ -250,9 +236,7 @@ struct WritableBuffer { } constexpr void skip_front(size_type n) noexcept { -#ifndef NDEBUG assert(size >= n); -#endif data += n; size -= n; @@ -263,10 +247,8 @@ struct WritableBuffer { * size attribute to retain the old end address. */ void MoveFront(pointer new_data) noexcept { -#ifndef NDEBUG assert(IsNull() == (new_data == nullptr)); assert(new_data <= end()); -#endif size = end() - new_data; data = new_data; @@ -277,10 +259,8 @@ struct WritableBuffer { * size). */ void SetEnd(pointer new_end) noexcept { -#ifndef NDEBUG assert(IsNull() == (new_end == nullptr)); assert(new_end >= begin()); -#endif size = new_end - data; }