From 309da5e7d12485fe61fdf40ec54897c275ee2ba3 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 29 Sep 2025 22:46:44 -0700 Subject: [PATCH] [ADT] Make non-const functions forward to const versions (NFC) These functions all correspond to their respective const versions. This patch uses the "const_cast" trick to forward to the const versions. --- llvm/include/llvm/Support/TrailingObjects.h | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) 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 T *getTrailingObjects() { - verifyTrailingObjectsAssertions(); - // Forwards to an impl function with overloads, since member - // function templates can't be specialized. - return this->getTrailingObjectsImpl( - static_cast(this), TrailingObjectsBase::OverloadToken()); + return const_cast( + static_cast(this)->getTrailingObjects()); } // 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(); - return this->getTrailingObjectsImpl( - static_cast(this), - TrailingObjectsBase::OverloadToken()); + return const_cast( + static_cast(this)->getTrailingObjects()); } // Functions that return the trailing objects as ArrayRefs. @@ -342,9 +334,8 @@ class TrailingObjects } template T *getTrailingObjectsNonStrict() { - verifyTrailingObjectsAssertions(); - return this->getTrailingObjectsImpl( - static_cast(this), TrailingObjectsBase::OverloadToken()); + return const_cast(static_cast(this) + ->getTrailingObjectsNonStrict()); } template