Skip to content

Commit 728ac3a

Browse files
authored
run some tests and fixes for C++20 (#663)
1 parent 16919dd commit 728ac3a

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ jobs:
102102
gcc9:
103103
containerImage: gcc:9
104104
cli11.std: 17
105+
gcc11:
106+
containerImage: gcc:11
107+
cli11.std: 20
105108
gcc8:
106109
containerImage: gcc:8
107110
cli11.std: 17

include/CLI/App.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,10 @@ class App {
799799

800800
/// Add option for flag with integer result - defaults to allowing multiple passings, but can be forced to one
801801
/// if `multi_option_policy(CLI::MultiOptionPolicy::Throw)` is used.
802-
template <typename T,
803-
enable_if_t<std::is_constructible<T, std::int64_t>::value && !is_bool<T>::value, detail::enabler> =
804-
detail::dummy>
802+
template <
803+
typename T,
804+
enable_if_t<std::is_constructible<T, std::int64_t>::value && !std::is_const<T>::value && !is_bool<T>::value,
805+
detail::enabler> = detail::dummy>
805806
Option *add_flag(std::string flag_name,
806807
T &flag_count, ///< A variable holding the count
807808
std::string flag_description = "") {

tests/AppTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,3 +2308,11 @@ TEST_CASE_METHOD(TApp, "logFormSingleDash", "[app]") {
23082308
CHECK(veryverbose);
23092309
CHECK(veryveryverbose);
23102310
}
2311+
2312+
TEST_CASE("C20_compile", "simple") {
2313+
CLI::App app{"test"};
2314+
auto flag = app.add_flag("--flag", "desc");
2315+
2316+
app.parse("--flag");
2317+
CHECK_FALSE(flag->empty());
2318+
}

tests/OptionalTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,19 @@ TEST_CASE_METHOD(TApp, "BoostOptionalEnumTest", "[optional]") {
239239
auto dstring = optptr->get_default_str();
240240
CHECK(dstring.empty());
241241
run();
242-
CHECK(!opt);
242+
auto checkOpt = static_cast<bool>(opt);
243+
CHECK_FALSE(checkOpt);
243244

244245
args = {"-v", "3"};
245246
run();
246-
CHECK(opt);
247+
checkOpt = static_cast<bool>(opt);
248+
CHECK(checkOpt);
247249
CHECK(*opt == eval::val3);
248250
opt = {};
249251
args = {"--val", "1"};
250252
run();
251-
CHECK(opt);
253+
checkOpt = static_cast<bool>(opt);
254+
CHECK(checkOpt);
252255
CHECK(*opt == eval::val1);
253256
}
254257

0 commit comments

Comments
 (0)