We recently (commit 6a5d9ff261) started
to use std::source_location instead of std::experimental::source_location.
However, this does not work on clang 14, because libc++ 12's
<source_location> only works if __builtin_source_location, and that is
not available on clang 14.
clang 15 is just three months old, and several relatively-recent
distributions still carry clang 14 so it would be nice to support it
as well.
So this patch adds a trivial compatibility header file, which, when
included and compiled with clang 14, it aliases the functional
std::experimental::source_location to std::source_location.
It turns out it's enough to include the new header file from three
headers that included <source_location> - I guess all other uses
of source_location depend on those header files directly or indirectly.
We may later need to include the compatibility header file in additional
places, bug for now we don't.
Refs #12259
Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Closes #12265
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
/*
|
|
* Copyright (C) 2020-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <source_location>
|
|
#include "utils/source_location-compat.hh"
|
|
#include <string>
|
|
|
|
#include <fmt/format.h>
|
|
|
|
// Thread safe alternatives to BOOST_REQUIRE_*, BOOST_CHECK_* and BOOST_FAIL().
|
|
// Use these if instead of the BOOST provided macros if you want to use them on
|
|
// multiple shards, to avoid problems due to the BOOST versions not being thread
|
|
// safe.
|
|
|
|
namespace tests {
|
|
|
|
[[nodiscard]] bool do_check(bool condition, std::source_location sl, std::string_view msg);
|
|
|
|
[[nodiscard]] inline bool check(bool condition, std::source_location sl = std::source_location::current()) {
|
|
return do_check(condition, sl, {});
|
|
}
|
|
|
|
template <typename LHS, typename RHS>
|
|
[[nodiscard]] bool check_equal(const LHS& lhs, const RHS& rhs, std::source_location sl = std::source_location::current()) {
|
|
const auto condition = (lhs == rhs);
|
|
return do_check(condition, sl, fmt::format("{} {}= {}", lhs, condition ? "=" : "!", rhs));
|
|
}
|
|
|
|
void do_require(bool condition, std::source_location sl, std::string_view msg);
|
|
|
|
inline void require(bool condition, std::source_location sl = std::source_location::current()) {
|
|
do_require(condition, sl, {});
|
|
}
|
|
|
|
template <typename LHS, typename RHS>
|
|
void require_equal(const LHS& lhs, const RHS& rhs, std::source_location sl = std::source_location::current()) {
|
|
const auto condition = (lhs == rhs);
|
|
do_require(condition, sl, fmt::format("{} {}= {}", lhs, condition ? "=" : "!", rhs));
|
|
}
|
|
|
|
void fail(std::string_view msg, std::source_location sl = std::source_location::current());
|
|
|
|
}
|