From f92bae887f245264fcb548f86821440420d8903c Mon Sep 17 00:00:00 2001 From: Max Kellermann <mk@cm4all.com> Date: Tue, 31 May 2022 16:10:28 +0200 Subject: [PATCH] util/Manual: add `noexcept` --- src/util/Manual.hxx | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/util/Manual.hxx b/src/util/Manual.hxx index 78006ff74..f3d424e11 100644 --- a/src/util/Manual.hxx +++ b/src/util/Manual.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2017 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,8 +27,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MANUAL_HXX -#define MANUAL_HXX +#pragma once #include <cassert> #include <new> @@ -56,7 +55,7 @@ class Manual { public: #ifndef NDEBUG - ~Manual() { + ~Manual() noexcept { assert(!initialized); } #endif @@ -64,7 +63,7 @@ public: /** * Cast a value reference to the containing Manual instance. */ - static constexpr Manual<T> &Cast(T &value) { + static constexpr Manual<T> &Cast(T &value) noexcept { return reinterpret_cast<Manual<T> &>(value); } @@ -80,7 +79,7 @@ public: #endif } - void Destruct() { + void Destruct() noexcept { assert(initialized); T &t = Get(); @@ -91,33 +90,33 @@ public: #endif } - T &Get() { + T &Get() noexcept { assert(initialized); void *p = static_cast<void *>(data); return *static_cast<T *>(p); } - const T &Get() const { + const T &Get() const noexcept { assert(initialized); const void *p = static_cast<const void *>(data); return *static_cast<const T *>(p); } - operator T &() { + operator T &() noexcept { return Get(); } - operator const T &() const { + operator const T &() const noexcept { return Get(); } - T *operator->() { + T *operator->() noexcept { return &Get(); } - const T *operator->() const { + const T *operator->() const noexcept { return &Get(); } }; @@ -125,5 +124,3 @@ public: #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif - -#endif