From 19e38fbae692cecfee661969b4d9f4aa38260f46 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Mon, 12 Jan 2026 15:11:05 +0100 Subject: [PATCH 1/2] [hist] Add RBinIndex conversion overloads This avoids sign conversion warnings for signed integers, for example from literals. We then need all overloads to guarantee one unambiguous constructor candidate following integer promotion. --- hist/histv7/inc/ROOT/RBinIndex.hxx | 31 +++++++++++++++++++++++++++++- hist/histv7/test/hist_index.cxx | 18 +++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/hist/histv7/inc/ROOT/RBinIndex.hxx b/hist/histv7/inc/ROOT/RBinIndex.hxx index d7954f56a7f34..475cc4d62263f 100644 --- a/hist/histv7/inc/ROOT/RBinIndex.hxx +++ b/hist/histv7/inc/ROOT/RBinIndex.hxx @@ -28,6 +28,9 @@ class RBinIndex final { // We use std::uint64_t instead of std::size_t for the index because for sparse histograms, not all bins have to be // allocated in memory. However, we require that the index has at least that size. static_assert(sizeof(std::uint64_t) >= sizeof(std::size_t), "index type not large enough to address all bins"); + // During construction, we expect that any standard integer fits in std::uint64_t. + static_assert(sizeof(std::uint64_t) >= sizeof(unsigned long long), + "index type not large enough to store any standard integer"); std::uint64_t fIndex = kInvalidIndex; @@ -36,7 +39,33 @@ public: RBinIndex() = default; /// Construct a bin index for a normal bin. - RBinIndex(std::uint64_t index) : fIndex(index) { assert(IsNormal()); } + RBinIndex(unsigned int index) : RBinIndex(static_cast(index)) {} + + /// Construct a bin index for a normal bin. + RBinIndex(unsigned long index) : RBinIndex(static_cast(index)) {} + + /// Construct a bin index for a normal bin. + RBinIndex(unsigned long long index) : fIndex(index) { assert(IsNormal()); } + + /// Construct a bin index for a normal bin. + /// + /// \param[in] index signed integer that must not be negative + RBinIndex(int index) : RBinIndex(static_cast(index)) {} + + /// Construct a bin index for a normal bin. + /// + /// \param[in] index signed integer that must not be negative + RBinIndex(long index) : RBinIndex(static_cast(index)) {} + + /// Construct a bin index for a normal bin. + /// + /// \param[in] index signed integer that must not be negative + RBinIndex(long long index) + { + assert(index >= 0); + fIndex = static_cast(index); + assert(IsNormal()); + } /// Return the index for a normal bin. std::uint64_t GetIndex() const diff --git a/hist/histv7/test/hist_index.cxx b/hist/histv7/test/hist_index.cxx index 93976a2532a3a..19591b7896350 100644 --- a/hist/histv7/test/hist_index.cxx +++ b/hist/histv7/test/hist_index.cxx @@ -4,6 +4,10 @@ #include #include +#ifndef TYPED_TEST_SUITE +#define TYPED_TEST_SUITE TYPED_TEST_CASE +#endif + TEST(RBinIndex, Constructor) { const RBinIndex invalid; @@ -152,6 +156,20 @@ TEST(RBinIndex, Relation) EXPECT_FALSE(underflow >= overflow); } +template +class RBinIndexConversion : public testing::Test {}; + +using IntegerTypes = testing::Types; +TYPED_TEST_SUITE(RBinIndexConversion, IntegerTypes); + +TYPED_TEST(RBinIndexConversion, Constructor) +{ + const TypeParam input = 1; + const RBinIndex index(input); + EXPECT_EQ(index.GetIndex(), 1); +} + using ROOT::Experimental::Internal::CreateBinIndexRange; TEST(RBinIndexRange, ConstructorCreate) From 1f3840eaebafa17cd8f017f9ee6556d463947173 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Wed, 14 Jan 2026 09:14:03 +0100 Subject: [PATCH 2/2] [ci] Enable compiler warnings in standalone histv7 --- .github/workflows/histv7.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/histv7.yml b/.github/workflows/histv7.yml index a3b152dbed370..365889d679e4a 100644 --- a/.github/workflows/histv7.yml +++ b/.github/workflows/histv7.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Configure - run: cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install -Dhistv7_benchmark=ON hist/histv7 + run: cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -Wpedantic -Wsign-conversion" -DCMAKE_INSTALL_PREFIX=install -Dhistv7_benchmark=ON hist/histv7 - name: Build run: cmake --build build - name: Install