Skip to content

Commit 48f786b

Browse files
committed
disallow passing pointer to utils::as_const() as it does nothing
1 parent a1e752f commit 48f786b

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ namespace utils {
419419
constexpr typename std::add_const<T>::type & as_const(T& t) noexcept
420420
{
421421
static_assert(!std::is_const<T>::value, "object is already const");
422+
static_assert(!std::is_pointer<T>::value, "object is a pointer");
422423
// NOLINTNEXTLINE(bugprone-return-const-ref-from-parameter) - potential false positive
423424
return t;
424425
}

test/testutils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,9 @@ class TestUtils : public TestFixture {
542542
ASSERT(c.written);
543543
}
544544
{
545-
C c;
546-
C* cp = &c;
547-
utils::as_const(cp)->f(); // (correctly) calls non-const version
548-
ASSERT(c.written);
545+
int i;
546+
auto cr = utils::as_const(i); // TODO: does nothing and should not be allowed
547+
(void)cr;
549548
}
550549
}
551550

0 commit comments

Comments
 (0)