diff --git a/lib/mu-contacts.cc b/lib/mu-contacts.cc index a76be29b..dfc9369c 100644 --- a/lib/mu-contacts.cc +++ b/lib/mu-contacts.cc @@ -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(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(g_ascii_tolower(c)); return djb; } }; diff --git a/lib/mu-message-flags.cc b/lib/mu-message-flags.cc index 0abe675a..0ac76e97 100644 --- a/lib/mu-message-flags.cc +++ b/lib/mu-message-flags.cc @@ -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 */ diff --git a/lib/mu-message-flags.hh b/lib/mu-message-flags.hh index 66459f8b..07c6e0d2 100644 --- a/lib/mu-message-flags.hh +++ b/lib/mu-message-flags.hh @@ -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; + } }; /** diff --git a/lib/mu-msg-sexp.cc b/lib/mu-msg-sexp.cc index 9546517c..d6f3b5f0 100644 --- a/lib/mu-msg-sexp.cc +++ b/lib/mu-msg-sexp.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2011-2020 Dirk-Jan C. Binnema +** Copyright (C) 2011-2022 Dirk-Jan C. Binnema ** ** 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); } diff --git a/lib/mu-parser.cc b/lib/mu-parser.cc index ab505436..d8287c47 100644 --- a/lib/mu-parser.cc +++ b/lib/mu-parser.cc @@ -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: diff --git a/lib/mu-store.cc b/lib/mu-store.cc index 6e4ae364..a5295c8b 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -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; diff --git a/lib/tests/test-mu-maildir.cc b/lib/tests/test-mu-maildir.cc index 31491551..2092f4c3 100644 --- a/lib/tests/test-mu-maildir.cc +++ b/lib/tests/test-mu-maildir.cc @@ -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)) { diff --git a/lib/tests/test-parser.cc b/lib/tests/test-parser.cc index 4459d69a..2e5fbfd2 100644 --- a/lib/tests/test-parser.cc +++ b/lib/tests/test-parser.cc @@ -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; diff --git a/lib/utils/mu-command-parser.cc b/lib/utils/mu-command-parser.cc index 552d0364..05f1e02d 100644 --- a/lib/utils/mu-command-parser.cc +++ b/lib/utils/mu-command-parser.cc @@ -162,6 +162,16 @@ Command::get_int(const Parameters& params, const std::string& argname) return ::atoi(it->value().c_str()); } +std::optional +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 Command::get_bool(const Parameters& params, const std::string& argname) { diff --git a/lib/utils/mu-command-parser.hh b/lib/utils/mu-command-parser.hh index cc592045..b7a47763 100644 --- a/lib/utils/mu-command-parser.hh +++ b/lib/utils/mu-command-parser.hh @@ -63,6 +63,7 @@ using ArgMap = std::unordered_map; using Parameters = Sexp::Seq; std::optional get_int(const Parameters& parms, const std::string& argname); +std::optional get_unsigned(const Parameters& parms, const std::string& argname); std::optional get_bool(const Parameters& parms, const std::string& argname); std::optional get_string(const Parameters& parms, const std::string& argname); std::optional 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); diff --git a/lib/utils/mu-error.hh b/lib/utils/mu-error.hh index 92ddd5ef..8baea197 100644 --- a/lib/utils/mu-error.hh +++ b/lib/utils/mu-error.hh @@ -103,7 +103,7 @@ struct Error final : public std::exception { * DTOR * */ - virtual ~Error() = default; + virtual ~Error() override = default; /** * Get the descriptiove message. diff --git a/lib/utils/mu-result.hh b/lib/utils/mu-result.hh index 8c6754a0..8e304fdc 100644 --- a/lib/utils/mu-result.hh +++ b/lib/utils/mu-result.hh @@ -38,7 +38,9 @@ template using Result = tl::expected; * @return a success Result */ template -typename Result::expected +class Result::expected +// note: "class", not "typename"; +// https://stackoverflow.com/questions/46412754/class-name-injection-and-constructors Ok(T&& t) { return std::move(t); diff --git a/lib/utils/mu-sexp.hh b/lib/utils/mu-sexp.hh index 82613c43..6c835e93 100644 --- a/lib/utils/mu-sexp.hh +++ b/lib/utils/mu-sexp.hh @@ -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)} diff --git a/lib/utils/mu-util.h b/lib/utils/mu-util.h index 6c016372..d41aa234 100644 --- a/lib/utils/mu-util.h +++ b/lib/utils/mu-util.h @@ -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; diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index b5eb3b50..868ffe6a 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -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(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. diff --git a/mu/mu-cmd-find.cc b/mu/mu-cmd-find.cc index e0b34d52..3b6c94e7 100644 --- a/mu/mu-cmd-find.cc +++ b/mu/mu-cmd-find.cc @@ -51,8 +51,8 @@ struct OutputInfo { Option 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;