From d69e578519840b9b74eff26ac01465ac07698063 Mon Sep 17 00:00:00 2001 From: jpr42 <109434725+jpr42@users.noreply.github.com> Date: Tue, 1 Nov 2022 11:07:47 -0600 Subject: [PATCH] clang-tidy: performance-noexcept-move-constructor (#1063) I ran GSL through clang-tidy with the performance-* checks https://releases.llvm.org/15.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/performance/noexcept-move-constructor.html --- include/gsl/pointers | 4 +++- include/gsl/string_span | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/gsl/pointers b/include/gsl/pointers index 94a7192..17c756b 100644 --- a/include/gsl/pointers +++ b/include/gsl/pointers @@ -267,7 +267,9 @@ public: constexpr strict_not_null(const strict_not_null& other) : not_null(other) {} - strict_not_null(strict_not_null&& other) = default; + // To avoid invalidating the "not null" invariant, the contained pointer is actually copied + // instead of moved. If it is a custom pointer, its constructor could in theory throw exceptions. + strict_not_null(strict_not_null&& other) noexcept(std::is_nothrow_copy_constructible::value) = default; strict_not_null(const strict_not_null& other) = default; strict_not_null& operator=(const strict_not_null& other) = default; strict_not_null& operator=(const not_null& other) diff --git a/include/gsl/string_span b/include/gsl/string_span index 397c561..658cf84 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -437,13 +437,13 @@ public: constexpr basic_zstring_span(const basic_zstring_span& other) = default; // move - constexpr basic_zstring_span(basic_zstring_span && other) = default; + constexpr basic_zstring_span(basic_zstring_span && other) noexcept = default; // assign constexpr basic_zstring_span& operator=(const basic_zstring_span& other) = default; // move assign - constexpr basic_zstring_span& operator=(basic_zstring_span&& other) = default; + constexpr basic_zstring_span& operator=(basic_zstring_span&& other) noexcept = default; constexpr bool empty() const noexcept { return false; }