]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: use constexpr string_view as input to format()
authorCasey Bodley <cbodley@redhat.com>
Mon, 14 Feb 2022 22:58:05 +0000 (17:58 -0500)
committerKefu Chai <tchaikov@gmail.com>
Tue, 22 Mar 2022 15:26:54 +0000 (23:26 +0800)
resolves a c++20 compilation error with clang13:

ceph/src/mgr/Mgr.cc:602:42: error: call to consteval function 'fmt::basic_format_string<char, const std::basic_string<char> &>::basic_format_string<const char *, 0>' is not a constant expression
    monc->start_mon_command({fmt::format(cmd, name)}, {},
                                         ^
ceph/src/fmt/include/fmt/core.h:2839:56: note: read of non-constexpr variable 'cmd' is not allowed in a constant expression
  FMT_CONSTEVAL basic_format_string(const S& s) : str_(s) {
                                                       ^
ceph/src/mgr/Mgr.cc:602:42: note: in call to 'basic_format_string(cmd)'
    monc->start_mon_command({fmt::format(cmd, name)}, {},
                                         ^
ceph/src/mgr/Mgr.cc:601:17: note: declared here
    const char* cmd = R"({{"prefix": "mon metadata", "id": "{}"}})";
                ^

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/mgr/Mgr.cc

index d7aebd8fceca8a24cc26e04c7e6ead6ecf90e31b..32c92466bbce5758abe3db64184c905fbf731177 100644 (file)
@@ -598,7 +598,7 @@ void Mgr::handle_mon_map()
       continue;
     }
     auto c = new MetadataUpdate(daemon_state, k);
-    const char* cmd = R"({{"prefix": "mon metadata", "id": "{}"}})";
+    constexpr std::string_view cmd = R"({{"prefix": "mon metadata", "id": "{}"}})";
     monc->start_mon_command({fmt::format(cmd, name)}, {},
                            &c->outbl, &c->outs, c);
   }