[llvm] e457307 - [ADT] Make non-const functions forward to const versions (NFC) (#161323)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 08:56:40 PDT 2025
Author: Kazu Hirata
Date: 2025-09-30T08:56:36-07:00
New Revision: e457307b8aedbcb70430f2f907057589fa363600
URL: https://github.com/llvm/llvm-project/commit/e457307b8aedbcb70430f2f907057589fa363600
DIFF: https://github.com/llvm/llvm-project/commit/e457307b8aedbcb70430f2f907057589fa363600.diff
LOG: [ADT] Make non-const functions forward to const versions (NFC) (#161323)
These functions all correspond to their respective const versions.
This patch uses the "const_cast" trick to forward to the const
versions.
Added:
Modified:
llvm/include/llvm/Support/TrailingObjects.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/TrailingObjects.h b/llvm/include/llvm/Support/TrailingObjects.h
index 3eb7c0bd1f379..dc03285c4994b 100644
--- a/llvm/include/llvm/Support/TrailingObjects.h
+++ b/llvm/include/llvm/Support/TrailingObjects.h
@@ -284,11 +284,8 @@ class TrailingObjects
/// (which must be one of those specified in the class template). The
/// array may have zero or more elements in it.
template <typename T> T *getTrailingObjects() {
- verifyTrailingObjectsAssertions<true>();
- // Forwards to an impl function with overloads, since member
- // function templates can't be specialized.
- return this->getTrailingObjectsImpl(
- static_cast<BaseTy *>(this), TrailingObjectsBase::OverloadToken<T>());
+ return const_cast<T *>(
+ static_cast<const TrailingObjects *>(this)->getTrailingObjects<T>());
}
// getTrailingObjects() specialization for a single trailing type.
@@ -306,13 +303,8 @@ class TrailingObjects
}
FirstTrailingType *getTrailingObjects() {
- static_assert(sizeof...(TrailingTys) == 1,
- "Can use non-templated getTrailingObjects() only when there "
- "is a single trailing type");
- verifyTrailingObjectsAssertions<false>();
- return this->getTrailingObjectsImpl(
- static_cast<BaseTy *>(this),
- TrailingObjectsBase::OverloadToken<FirstTrailingType>());
+ return const_cast<FirstTrailingType *>(
+ static_cast<const TrailingObjects *>(this)->getTrailingObjects());
}
// Functions that return the trailing objects as ArrayRefs.
@@ -342,9 +334,8 @@ class TrailingObjects
}
template <typename T> T *getTrailingObjectsNonStrict() {
- verifyTrailingObjectsAssertions<false>();
- return this->getTrailingObjectsImpl(
- static_cast<BaseTy *>(this), TrailingObjectsBase::OverloadToken<T>());
+ return const_cast<T *>(static_cast<const TrailingObjects *>(this)
+ ->getTrailingObjectsNonStrict<T>());
}
template <typename T>
More information about the llvm-commits
mailing list