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; } }