lib: fix clang compatibility / warnings

This commit is contained in:
Dirk-Jan C. Binnema 2022-02-18 10:49:56 +02:00
parent d2e6cfdf70
commit c0da564bba
16 changed files with 48 additions and 22 deletions

View File

@ -49,7 +49,7 @@ struct EmailHash {
{
std::size_t djb = 5381; // djb hash
for (const auto c : email)
djb = ((djb << 5) + djb) + g_ascii_tolower(c);
djb = ((djb << 5) + djb) + static_cast<size_t>(g_ascii_tolower(c));
return djb;
}
};
@ -66,7 +66,7 @@ struct ContactInfoHash {
{
std::size_t djb = 5381; // djb hash
for (const auto c : ci.email)
djb = ((djb << 5) + djb) + g_ascii_tolower(c);
djb = ((djb << 5) + djb) + static_cast<size_t>(g_ascii_tolower(c));
return djb;
}
};

View File

@ -75,6 +75,9 @@ static_assert(message_flag_info("attach")->flag == MessageFlags::HasAttachment);
static_assert(!message_flag_info("fnorb"));
static_assert(message_flag_info('D')->shortcut_lower() == 'd');
static_assert(message_flag_info('u')->shortcut_lower() == 'u');
/*
* message_flags_from_expr
*/

View File

@ -92,6 +92,16 @@ struct MessageFlagInfo {
char shortcut; /**< Shortcut character */
std::string_view name; /**< Name of the flag */
MessageFlagCategory category; /**< Flag category */
/**
* Get the lower-case version of shortcut
*
* @return lower-case shortcut
*/
constexpr char shortcut_lower() const {
return shortcut >= 'A' && shortcut <= 'Z' ?
shortcut + ('a' - 'A') : shortcut;
}
};
/**

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -87,7 +87,7 @@ add_list_post(Sexp::List& list, MuMsg* msg)
if (g_regex_match(rx, list_post, (GRegexMatchFlags)0, &minfo)) {
auto address = (char*)g_match_info_fetch(minfo, 1);
MuMsgContact contact{NULL, address};
MuMsgContact contact{NULL, address, {}, {}};
list.add_prop(":list-post", Sexp::make_list(make_contact_sexp(&contact)));
g_free(address);
}

View File

@ -118,7 +118,7 @@ process_value(const std::string& field, const std::string& value)
case MU_MSG_FIELD_ID_FLAGS:
if (const auto info{message_flag_info(value)}; info)
return std::string(1, ::tolower(info->shortcut));
return std::string(1, info->shortcut_lower());
break;
default:

View File

@ -55,7 +55,6 @@ constexpr auto RootMaildirKey = "maildir"; // XXX: make this 'root-maildir
constexpr auto ContactsKey = "contacts";
constexpr auto PersonalAddressesKey = "personal-addresses";
constexpr auto CreatedKey = "created";
constexpr auto LastIndexKey = "last-index"; /* time of last index */
constexpr auto BatchSizeKey = "batch-size";
constexpr auto DefaultBatchSize = 250'000U;
@ -73,7 +72,7 @@ constexpr auto ExpectedSchemaVersion = MU_STORE_SCHEMA_VERSION;
*
* @return the hash
*/
size_t get_hash64 (const char* str)
uint64_t get_hash64 (const char* str)
{
guint32 djbhash;
guint32 bkdrhash;

View File

@ -196,7 +196,7 @@ test_mu_maildir_flags_from_path(void)
}
}
static void
[[maybe_unused]] static void
assert_matches_regexp(const char* str, const char* rx)
{
if (!g_regex_match_simple(rx, str, (GRegexCompileFlags)0, (GRegexMatchFlags)0)) {

View File

@ -32,7 +32,7 @@ using namespace Mu;
struct Case {
const std::string expr;
const std::string expected;
WarningVec warnings;
WarningVec warnings{};
};
using CaseVec = std::vector<Case>;

View File

@ -162,6 +162,16 @@ Command::get_int(const Parameters& params, const std::string& argname)
return ::atoi(it->value().c_str());
}
std::optional<unsigned>
Command::get_unsigned(const Parameters& params, const std::string& argname)
{
if (auto val = get_int(params, argname); val && *val >= 0)
return val;
else
return std::nullopt;
}
std::optional<bool>
Command::get_bool(const Parameters& params, const std::string& argname)
{

View File

@ -63,6 +63,7 @@ using ArgMap = std::unordered_map<std::string, ArgInfo>;
using Parameters = Sexp::Seq;
std::optional<int> get_int(const Parameters& parms, const std::string& argname);
std::optional<unsigned> get_unsigned(const Parameters& parms, const std::string& argname);
std::optional<bool> get_bool(const Parameters& parms, const std::string& argname);
std::optional<std::string> get_string(const Parameters& parms, const std::string& argname);
std::optional<std::string> get_symbol(const Parameters& parms, const std::string& argname);
@ -76,6 +77,7 @@ static inline int
get_int_or(const Parameters& parms, const std::string& arg, int alt = 0) {
return get_int(parms, arg).value_or(alt);
}
static inline bool
get_bool_or(const Parameters& parms, const std::string& arg, bool alt = false) {
return get_bool(parms, arg).value_or(alt);

View File

@ -103,7 +103,7 @@ struct Error final : public std::exception {
* DTOR
*
*/
virtual ~Error() = default;
virtual ~Error() override = default;
/**
* Get the descriptiove message.

View File

@ -38,7 +38,9 @@ template <typename T> using Result = tl::expected<T, Error>;
* @return a success Result<T>
*/
template <typename T>
typename Result<T>::expected
class Result<T>::expected
// note: "class", not "typename";
// https://stackoverflow.com/questions/46412754/class-name-injection-and-constructors
Ok(T&& t)
{
return std::move(t);

View File

@ -296,7 +296,7 @@ struct Sexp {
return false;
else
return is_prop_list(list().begin() + 1, list().end());
};
}
private:
Sexp(Type typearg, std::string&& valuearg) : type_{typearg}, value_{std::move(valuearg)}

View File

@ -401,8 +401,8 @@ mu_util_get_hash (const char* str)
bkdrseed = 1313;
for(unsigned u = 0U; str[u]; ++u) {
djbhash = ((djbhash << 5) + djbhash) + str[u];
bkdrhash = bkdrhash * bkdrseed + str[u];
djbhash = ((djbhash << 5) + djbhash) + (unsigned)str[u];
bkdrhash = bkdrhash * bkdrseed + (unsigned)str[u];
}
hash = djbhash;

View File

@ -191,13 +191,13 @@ struct StopWatch {
StopWatch(const std::string name) : start_{Clock::now()}, name_{name} {}
~StopWatch()
{
const auto us{to_us(Clock::now() - start_)};
const auto us{static_cast<double>(to_us(Clock::now() - start_))};
if (us > 2000000)
g_debug("%s: finished after %0.1f s", name_.c_str(), us / 1000000.0);
g_debug("%s: finished after %0.1f s", name_.c_str(), us / 1000000);
else if (us > 2000)
g_debug("%s: finished after %0.1f ms", name_.c_str(), us / 1000.0);
g_debug("%s: finished after %0.1f ms", name_.c_str(), us / 1000);
else
g_debug("%s: finished after %" G_GINT64_FORMAT " us", name_.c_str(), us);
g_debug("%s: finished after %g us", name_.c_str(), us);
}
private:
@ -304,8 +304,8 @@ private:
constexpr ET operator~(ET e) { return MU_TO_ENUM(ET, ~(MU_TO_NUM(ET, e))); } \
constexpr bool any_of(ET e) { return MU_TO_NUM(ET, e) != 0; } \
constexpr bool none_of(ET e) { return MU_TO_NUM(ET, e) == 0; } \
constexpr ET& operator&=(ET& e1, ET e2) { return e1 = e1 & e2; } \
constexpr ET& operator|=(ET& e1, ET e2) { return e1 = e1 | e2; }
constexpr ET& operator&=(ET& e1, ET e2) { return e1 = e1 & e2; } \
constexpr ET& operator|=(ET& e1, ET e2) { return e1 = e1 | e2; } \
/**
* For unit tests, assert two std::string's are equal.

View File

@ -51,8 +51,8 @@ struct OutputInfo {
Option<QueryMatch&> match_info;
};
constexpr auto FirstOutput{OutputInfo{0, true, false}};
constexpr auto LastOutput{OutputInfo{0, false, true}};
constexpr auto FirstOutput{OutputInfo{0, true, false, {}, {}}};
constexpr auto LastOutput{OutputInfo{0, false, true, {}, {}}};
using OutputFunc = std::function<bool(MuMsg*, const OutputInfo&, const MuConfig*, GError**)>;