Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions private/rdf4cpp/parser/IStreamQuadIteratorSerdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cassert>
#include <cstddef>

#include <rdf4cpp/Assert.hpp>

namespace rdf4cpp::parser {

std::string_view IStreamQuadIterator::Impl::node_into_string_view(SerdNode const *node) noexcept {
Expand Down Expand Up @@ -132,8 +134,7 @@ nonstd::expected<Literal, SerdStatus> IStreamQuadIterator::Impl::get_literal(Ser
case SerdType::SERD_URI:
return this->get_iri(datatype);
default:
assert(false);
__builtin_unreachable();
RDF4CPP_UNREACHABLE;
}
} else {
return std::nullopt;
Expand Down
4 changes: 3 additions & 1 deletion private/rdf4cpp/regex/RegexReplacerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <cctype>
#include <sstream>

#include <rdf4cpp/Assert.hpp>

namespace rdf4cpp::regex {

namespace detail {
Expand All @@ -16,7 +18,7 @@ namespace detail {
* @throws RegexError if the substring s.substr(pos, 2) is an invalid group reference
*/
static void replace(std::string &s, size_t pos) {
assert(s[pos] == '$');
RDF4CPP_ASSERT(s[pos] == '$');
s[pos] = '\\';

if (pos == s.size() - 1 || !std::isdigit(s[pos + 1])) {
Expand Down
3 changes: 2 additions & 1 deletion private/rdf4cpp/writer/Prefixes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <rdf4cpp/datatypes/registry/FixedIdMappings.hpp>
#include <rdf4cpp/writer/TryWrite.hpp>
#include <rdf4cpp/Assert.hpp>

namespace rdf4cpp::writer {

Expand Down Expand Up @@ -52,7 +53,7 @@ static constexpr auto type_iri_buffer = make_type_iri_buf<1 << storage::identifi

// will only get called with fixed ids
inline bool write_fixed_type_iri(datatypes::registry::LiteralType t, BufWriterParts const writer, bool use_prefixes) noexcept {
assert(t.is_fixed());
RDF4CPP_ASSERT(t.is_fixed());

if (use_prefixes) {
auto const &p = detail::type_iri_buffer[t.to_underlying()];
Expand Down
32 changes: 32 additions & 0 deletions src/rdf4cpp/Assert.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef RDF4CPP_ASSERT_HPP
#define RDF4CPP_ASSERT_HPP

#include <iostream>

#ifdef NDEBUG

#define RDF4CPP_TOSTRING_2(x) #x
#define RDF4CPP_TOSTRING(x) RDF4CPP_TOSTRING_2(x)
#define RDF4CPP_ASSERT(expr) \
if (!(expr)) [[unlikely]] { \
std::cerr << "Assertion failed: " #expr " (" __FILE__ ":" RDF4CPP_TOSTRING(__LINE__) ")"; \
std::abort(); \
}

#define RDF4CPP_UNREACHABLE \
std::cerr << "Unreachable statement reached (" __FILE__ ":" RDF4CPP_TOSTRING(__LINE__) ")"; \
std::abort(); \
__builtin_unreachable();

#define RDF4CPP_DEBUG_UNREACHABLE(...) return __VA_ARGS__

#else

#define RDF4CPP_ASSERT(expr) assert(expr)
#define RDF4CPP_UNREACHABLE assert(false)
#define RDF4CPP_DEBUG_UNREACHABLE(...) assert(false)

#endif
#define RDF4CPP_DEBUG_ASSERT(expr) assert(expr)

#endif //RDF4CPP_ASSERT_HPP
4 changes: 2 additions & 2 deletions src/rdf4cpp/BigDecimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <rdf4cpp/Expected.hpp>
#include <rdf4cpp/InvalidNode.hpp>
#include <rdf4cpp/Assert.hpp>

namespace rdf4cpp {
enum struct RoundingMode {
Expand Down Expand Up @@ -363,8 +364,7 @@ struct BigDecimal {
return BigDecimal{v, e};
}
default:
assert(false);
__builtin_unreachable();
RDF4CPP_UNREACHABLE;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/rdf4cpp/BlankNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <rdf4cpp/InvalidNode.hpp>
#include <rdf4cpp/util/CharMatcher.hpp>
#include <rdf4cpp/writer/TryWrite.hpp>
#include <rdf4cpp/Assert.hpp>
#include <uni_algo/all.h>

#include <cstring>
Expand Down Expand Up @@ -39,7 +40,7 @@ namespace detail_bnode_inlining {
}

[[nodiscard]] constexpr InlinedRepr from_inlined(storage::identifier::NodeBackendID id) noexcept {
assert(id.is_inlined() && id.is_blank_node());
RDF4CPP_ASSERT(id.is_inlined() && id.is_blank_node());
return std::bit_cast<InlinedRepr>(id.node_id());
}

Expand Down
Loading
Loading