From 88e7dcfa86a8d674ae96b6071d7e39f8b47d9dda Mon Sep 17 00:00:00 2001 From: Asias He Date: Mon, 25 May 2015 16:38:08 +0800 Subject: [PATCH] Remove redundant const in static constexpr const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From http://en.cppreference.com/w/cpp/language/constexpr: A constexpr specifier used in an object declaration implies const. However, We can not change from static constexpr const char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y"; to static constexpr char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y"; The compiler complains: In file included from json/formatter.cc:22:0: json/formatter.hh:132:42: error: deprecated conversion from string constant to ‘char*’ [-Werror=write-strings] static constexpr char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y"; Since, unlike const, constexpr does not modify a type. It just applies to an object (or function), and incidentally implies const to the top-level type. --- core/future.hh | 12 ++++++------ core/memory.cc | 12 ++++++------ core/memory.hh | 6 +++--- core/thread.hh | 2 +- json/formatter.hh | 2 +- net/tcp.hh | 22 +++++++++++----------- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/core/future.hh b/core/future.hh index d9beea5c5a..f66912c515 100644 --- a/core/future.hh +++ b/core/future.hh @@ -219,8 +219,8 @@ struct future_state { template <> struct future_state<> { static_assert(sizeof(std::exception_ptr) == sizeof(void*), "exception_ptr not a pointer"); - static constexpr const bool move_noexcept = true; - static constexpr const bool copy_noexcept = true; + static constexpr bool move_noexcept = true; + static constexpr bool copy_noexcept = true; enum class state : uintptr_t { invalid = 0, future = 1, @@ -310,8 +310,8 @@ class promise { future_state _local_state; future_state* _state; std::unique_ptr _task; - static constexpr const bool move_noexcept = future_state::move_noexcept; - static constexpr const bool copy_noexcept = future_state::copy_noexcept; + static constexpr bool move_noexcept = future_state::move_noexcept; + static constexpr bool copy_noexcept = future_state::copy_noexcept; public: promise() noexcept : _state(&_local_state) {} promise(promise&& x) noexcept(move_noexcept) : _future(x._future), _state(x._state), _task(std::move(x._task)) { @@ -434,8 +434,8 @@ template class future { promise* _promise; future_state _local_state; // valid if !_promise - static constexpr const bool move_noexcept = future_state::move_noexcept; - static constexpr const bool copy_noexcept = future_state::copy_noexcept; + static constexpr bool move_noexcept = future_state::move_noexcept; + static constexpr bool copy_noexcept = future_state::copy_noexcept; private: future(promise* pr) noexcept : _promise(pr) { _promise->_future = this; diff --git a/core/memory.cc b/core/memory.cc index 291e298711..3d1c916148 100644 --- a/core/memory.cc +++ b/core/memory.cc @@ -73,9 +73,9 @@ namespace memory { -static constexpr const unsigned cpu_id_shift = 36; // FIXME: make dynamic -static constexpr const unsigned max_cpus = 256; -static constexpr const size_t cache_line_size = 64; +static constexpr unsigned cpu_id_shift = 36; // FIXME: make dynamic +static constexpr unsigned max_cpus = 256; +static constexpr size_t cache_line_size = 64; using pageidx = uint32_t; @@ -227,7 +227,7 @@ small_pool::size_to_idx(unsigned size) { class small_pool_array { public: - static constexpr const unsigned nr_small_pools = small_pool::size_to_idx(4 * page_size) + 1; + static constexpr unsigned nr_small_pools = small_pool::size_to_idx(4 * page_size) + 1; private: union u { small_pool a[nr_small_pools]; @@ -245,7 +245,7 @@ public: small_pool& operator[](unsigned idx) { return _u.a[idx]; } }; -static constexpr const size_t max_small_allocation +static constexpr size_t max_small_allocation = small_pool::idx_to_size(small_pool_array::nr_small_pools - 1); struct cross_cpu_free_item { @@ -262,7 +262,7 @@ struct cpu_pages { unsigned cpu_id = -1U; std::function)> reclaim_hook; std::vector reclaimers; - static constexpr const unsigned nr_span_lists = 32; + static constexpr unsigned nr_span_lists = 32; union pla { pla() { for (auto&& e : free_spans) { diff --git a/core/memory.hh b/core/memory.hh index 5b8d44ac2a..0c1b8a2e1e 100644 --- a/core/memory.hh +++ b/core/memory.hh @@ -30,9 +30,9 @@ namespace memory { // TODO: Use getpagesize() in order to learn a size of a system PAGE. -static constexpr const size_t page_bits = 12; -static constexpr const size_t page_size = 1 << page_bits; // 4K -static constexpr const size_t huge_page_size = 512 * page_size; // 2M +static constexpr size_t page_bits = 12; +static constexpr size_t page_size = 1 << page_bits; // 4K +static constexpr size_t huge_page_size = 512 * page_size; // 2M void configure(std::vector m, std::experimental::optional hugetlbfs_path = {}); diff --git a/core/thread.hh b/core/thread.hh index 2b205cc5d7..98b3f27cd1 100644 --- a/core/thread.hh +++ b/core/thread.hh @@ -46,7 +46,7 @@ extern thread_local jmp_buf g_unthreaded_context; // \c thread itself because \c thread is movable, and we want pointers // to this state to be captured. class thread_context { - static constexpr const size_t _stack_size = 128*1024; + static constexpr size_t _stack_size = 128*1024; std::unique_ptr _stack{new char[_stack_size]}; std::function _func; jmp_buf _context; diff --git a/json/formatter.hh b/json/formatter.hh index 27d0814857..7d895ad2fb 100644 --- a/json/formatter.hh +++ b/json/formatter.hh @@ -129,7 +129,7 @@ public: private: - constexpr static const char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y"; + static constexpr const char* TIME_FORMAT = "%a %b %d %I:%M:%S %Z %Y"; }; diff --git a/net/tcp.hh b/net/tcp.hh index 0ff9f4197e..5c951b5a15 100644 --- a/net/tcp.hh +++ b/net/tcp.hh @@ -212,17 +212,17 @@ private: class tcb : public enable_lw_shared_from_this { using clock_type = lowres_clock; - static constexpr const tcp_state CLOSED = tcp_state::CLOSED; - static constexpr const tcp_state LISTEN = tcp_state::LISTEN; - static constexpr const tcp_state SYN_SENT = tcp_state::SYN_SENT; - static constexpr const tcp_state SYN_RECEIVED = tcp_state::SYN_RECEIVED; - static constexpr const tcp_state ESTABLISHED = tcp_state::ESTABLISHED; - static constexpr const tcp_state FIN_WAIT_1 = tcp_state::FIN_WAIT_1; - static constexpr const tcp_state FIN_WAIT_2 = tcp_state::FIN_WAIT_2; - static constexpr const tcp_state CLOSE_WAIT = tcp_state::CLOSE_WAIT; - static constexpr const tcp_state CLOSING = tcp_state::CLOSING; - static constexpr const tcp_state LAST_ACK = tcp_state::LAST_ACK; - static constexpr const tcp_state TIME_WAIT = tcp_state::TIME_WAIT; + static constexpr tcp_state CLOSED = tcp_state::CLOSED; + static constexpr tcp_state LISTEN = tcp_state::LISTEN; + static constexpr tcp_state SYN_SENT = tcp_state::SYN_SENT; + static constexpr tcp_state SYN_RECEIVED = tcp_state::SYN_RECEIVED; + static constexpr tcp_state ESTABLISHED = tcp_state::ESTABLISHED; + static constexpr tcp_state FIN_WAIT_1 = tcp_state::FIN_WAIT_1; + static constexpr tcp_state FIN_WAIT_2 = tcp_state::FIN_WAIT_2; + static constexpr tcp_state CLOSE_WAIT = tcp_state::CLOSE_WAIT; + static constexpr tcp_state CLOSING = tcp_state::CLOSING; + static constexpr tcp_state LAST_ACK = tcp_state::LAST_ACK; + static constexpr tcp_state TIME_WAIT = tcp_state::TIME_WAIT; tcp_state _state = CLOSED; tcp& _tcp; connection* _conn = nullptr;