diff --git a/packages/tpetra/core/src/Tpetra_Details_FixedHashTable_decl.hpp b/packages/tpetra/core/src/Tpetra_Details_FixedHashTable_decl.hpp index f533afa7e1b8..c56e9d7f4441 100644 --- a/packages/tpetra/core/src/Tpetra_Details_FixedHashTable_decl.hpp +++ b/packages/tpetra/core/src/Tpetra_Details_FixedHashTable_decl.hpp @@ -429,9 +429,7 @@ class FixedHashTable { /// In Tpetra::Map, this corresponds to the maximum global index /// (local to the MPI process). /// @remark It will be set in @ref init. - KeyType maxKey_ = ::Kokkos::ArithTraits::is_integer ? - ::Kokkos::ArithTraits::min() : - -::Kokkos::ArithTraits::max(); + KeyType maxKey_ = ::Kokkos::ArithTraits::max(); /// \brief Minimum value. /// @@ -461,9 +459,7 @@ class FixedHashTable { /// In that case, the initial contiguous sequence of keys may have /// length 1 or more. Length 1 means that the sequence is trivial /// (there are no initial contiguous keys). - KeyType lastContigKey_ = ::Kokkos::ArithTraits::is_integer ? - ::Kokkos::ArithTraits::min() : - -::Kokkos::ArithTraits::max(); + KeyType lastContigKey_ = ::Kokkos::ArithTraits::max(); /// \brief Whether the table was created using one of the /// constructors that assume contiguous values. diff --git a/packages/tpetra/core/test/HashTable/FixedHashTableTest.cpp b/packages/tpetra/core/test/HashTable/FixedHashTableTest.cpp index 482ec0da1233..12b6f5acffd1 100644 --- a/packages/tpetra/core/test/HashTable/FixedHashTableTest.cpp +++ b/packages/tpetra/core/test/HashTable/FixedHashTableTest.cpp @@ -1094,6 +1094,16 @@ namespace { // (anonymous) out << "Got to the end!" << endl; } +//! @test Check that a default-initialized @ref FixedHashTable claims 0 pairs. This test was proposed in issue #13034. +TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(FixedHashTable_T, ZeroPairsOnDefaultInit, ValueType, KeyType, DeviceType) + { + using fixed_hash_table_t = Tpetra::Details::FixedHashTable; + + fixed_hash_table_t table {}; + + TEST_EQUALITY_CONST(table.numPairs(), 0); + } + // // Instantiations of the templated unit test(s) above. // @@ -1116,7 +1126,8 @@ namespace { // (anonymous) TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( FixedHashTable_T, NoncontigKeysAndVals, LO, GO, DEVICE ) \ TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( FixedHashTable_T, DuplicateKeys, LO, GO, DEVICE ) \ TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( FixedHashTable_T, CopyCtorNoDupKeys, LO, GO, DEVICE ) \ - TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( FixedHashTable_T, CopyCtorDupKeys, LO, GO, DEVICE ) + TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( FixedHashTable_T, CopyCtorDupKeys, LO, GO, DEVICE ) \ + TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( FixedHashTable_T, ZeroPairsOnDefaultInit, LO, GO, DEVICE ) // The typedefs below are there because macros don't like arguments // with commas in them.