From ae29a41fa780516d73f3ba6462b0b9e94a7ad39d Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 31 Mar 2026 11:12:13 +0200 Subject: [PATCH] disallow passing pointer to `utils::as_const()` as it does nothing --- lib/utils.h | 1 + test/testutils.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils.h b/lib/utils.h index 6f410af3dbc..14f5382a8bf 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -419,6 +419,7 @@ namespace utils { constexpr typename std::add_const::type & as_const(T& t) noexcept { static_assert(!std::is_const::value, "object is already const"); + static_assert(!std::is_pointer::value, "object is a pointer"); // NOLINTNEXTLINE(bugprone-return-const-ref-from-parameter) - potential false positive return t; } diff --git a/test/testutils.cpp b/test/testutils.cpp index b3da9b1f6dc..85da8c6c595 100644 --- a/test/testutils.cpp +++ b/test/testutils.cpp @@ -542,10 +542,9 @@ class TestUtils : public TestFixture { ASSERT(c.written); } { - C c; - C* cp = &c; - utils::as_const(cp)->f(); // (correctly) calls non-const version - ASSERT(c.written); + int i = 0; + auto cr = utils::as_const(i); // TODO: does nothing and should not be allowed + (void)cr; } }