Commit 728ac3a877d0ae9f6733a710165ad7acfd4c107a

Authored by Philip Top
Committed by GitHub
1 parent 16919dd1

run some tests and fixes for C++20 (#663)

azure-pipelines.yml
... ... @@ -102,6 +102,9 @@ jobs:
102 102 gcc9:
103 103 containerImage: gcc:9
104 104 cli11.std: 17
  105 + gcc11:
  106 + containerImage: gcc:11
  107 + cli11.std: 20
105 108 gcc8:
106 109 containerImage: gcc:8
107 110 cli11.std: 17
... ...
include/CLI/App.hpp
... ... @@ -799,9 +799,10 @@ class App {
799 799  
800 800 /// Add option for flag with integer result - defaults to allowing multiple passings, but can be forced to one
801 801 /// 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>
805 806 Option *add_flag(std::string flag_name,
806 807 T &flag_count, ///< A variable holding the count
807 808 std::string flag_description = "") {
... ...
tests/AppTest.cpp
... ... @@ -2308,3 +2308,11 @@ TEST_CASE_METHOD(TApp, &quot;logFormSingleDash&quot;, &quot;[app]&quot;) {
2308 2308 CHECK(veryverbose);
2309 2309 CHECK(veryveryverbose);
2310 2310 }
  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
... ... @@ -239,16 +239,19 @@ TEST_CASE_METHOD(TApp, &quot;BoostOptionalEnumTest&quot;, &quot;[optional]&quot;) {
239 239 auto dstring = optptr->get_default_str();
240 240 CHECK(dstring.empty());
241 241 run();
242   - CHECK(!opt);
  242 + auto checkOpt = static_cast<bool>(opt);
  243 + CHECK_FALSE(checkOpt);
243 244  
244 245 args = {"-v", "3"};
245 246 run();
246   - CHECK(opt);
  247 + checkOpt = static_cast<bool>(opt);
  248 + CHECK(checkOpt);
247 249 CHECK(*opt == eval::val3);
248 250 opt = {};
249 251 args = {"--val", "1"};
250 252 run();
251   - CHECK(opt);
  253 + checkOpt = static_cast<bool>(opt);
  254 + CHECK(checkOpt);
252 255 CHECK(*opt == eval::val1);
253 256 }
254 257  
... ...