Skip to content

Commit

Permalink
Use #ifdef to avoid errors when -Wundef is used.
Browse files Browse the repository at this point in the history
Example:
absl/hash/internal/hash.h:342:5: error: 'ABSL_HAVE_INTRINSIC_INT128' is not defined, evaluates to 0 [-Werror,-Wundef]
  342 | #if ABSL_HAVE_INTRINSIC_INT128
PiperOrigin-RevId: 706686332
Change-Id: I77639ba4826ea7a40f3f05e9885c795db3376ddd
  • Loading branch information
Abseil Team authored and copybara-github committed Dec 16, 2024
1 parent 3de434a commit 5c28547
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 54 deletions.
53 changes: 0 additions & 53 deletions absl/container/internal/raw_hash_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2477,59 +2477,6 @@ TYPED_TEST(SooTest, IterationOrderChangesByInstance) {
}
}

TYPED_TEST(SooTest, RelativeIterationOrderChangesByInstance) {
for (bool do_reserve : {false, true}) {
for (size_t size : {2u, 3u, 4u, 5u}) {
SCOPED_TRACE(absl::StrCat("size: ", size, " do_reserve: ", do_reserve));
std::set<std::pair<int64_t, int64_t>> relative_orders;
auto str = [&] {
std::string out;
for (auto p : relative_orders) {
absl::StrAppend(&out, "{", p.first, ",", p.second, "}", "|");
}
return out;
};
const size_t expected_num_orders = size * (size - 1);

std::vector<std::vector<TypeParam>> tables;
for (int i = 0; relative_orders.size() < expected_num_orders; ++i) {
static constexpr int kBatchSize = 100;
ASSERT_LE(i * kBatchSize, 500)
<< "Relative iteration order remained the same across "
"many attempts with size "
<< size << ". Found " << relative_orders.size()
<< " out of expected " << expected_num_orders << " orders found "
<< str();

std::vector<TypeParam> batch(kBatchSize);
if (do_reserve) {
for (auto& table : batch) {
table.reserve(size);
}
}
// Insert into the tables one by one in order to avoid reusing the same
// memory that was freed by the previous table resize.
for (size_t value = 0; value < size; ++value) {
for (auto& table : batch) {
table.insert(value);
}
}

for (const auto& table : batch) {
auto order = OrderOfIteration(table);
for (auto it = order.begin(); it != order.end(); ++it) {
for (auto it2 = std::next(it); it2 != order.end(); ++it2) {
relative_orders.emplace(*it, *it2);
}
}
}

tables.push_back(std::move(batch));
}
}
}
}

TYPED_TEST(SooTest, IterationOrderChangesOnRehash) {
// We test different sizes with many small numbers, because small table
// resize has a different codepath.
Expand Down
2 changes: 1 addition & 1 deletion absl/hash/internal/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ struct is_uniquely_represented<
template <>
struct is_uniquely_represented<bool> : std::false_type {};

#if ABSL_HAVE_INTRINSIC_INT128
#ifdef ABSL_HAVE_INTRINSIC_INT128
// Specialize the trait for GNU extension types.
template <>
struct is_uniquely_represented<__int128> : std::true_type {};
Expand Down

0 comments on commit 5c28547

Please sign in to comment.