rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.83k stars 313 forks source link

Bear fails to build against latest fmt #535

Closed EmmaJaneBonestell closed 1 year ago

EmmaJaneBonestell commented 1 year ago

Describe the bug

In file included from 
Bear/source/citnames/source/semantic/Semantic.cc:23:
In file included from include/fmt/std.h:19:
include/fmt/format.h:4197:30: error: no matching member function for call to 'format'
 4197 |       out = value_formatter_.format(*it, ctx);
      |             ~~~~~~~~~~~~~~~~~^~~~~~
include/fmt/core.h:1306:22: note: in instantiation of function template specialization 'fmt::formatter<fmt::join_view<__gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>, __gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>>>::format<fmt::basic_format_context<fmt::appender, char>>' requested here
 1306 |     ctx.advance_to(f.format(*static_cast<qualified_type*>(arg), ctx));
      |                      ^
include/fmt/core.h:1289:21: note: in instantiation of function template specialization 'fmt::detail::value<fmt::basic_format_context<fmt::appender, char>>::format_custom_arg<fmt::join_view<__gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>, __gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>>, fmt::formatter<fmt::join_view<__gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>, __gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>>>>' requested here
 1289 |     custom.format = format_custom_arg<
      |                     ^
Bear/source/citnames/source/semantic/Semantic.cc:96:38: note: in instantiation of function template specialization 'fmt::format<fmt::join_view<__gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>, __gnu_cxx::__normal_iterator<const std::filesystem::path *, std::vector<std::filesystem::path>>>>' requested here
   96 |             << ", sources: " << fmt::format("[{}]", fmt::join(sources.begin(), sources.end(), ", "))
      |                                      ^
include/fmt/core.h:2709:22: note: candidate function template not viable: no known conversion from 'const std::filesystem::path' to 'const fmt::basic_string_view<char>' for 1st argument
 2709 |   FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const
      |                      ^
In file included from 
Bear/source/citnames/source/semantic/Semantic.cc:23:
In file included from include/fmt/std.h:19:
include/fmt/format.h:4202:32: error: no matching member function for call to 'format'
 4202 |         out = value_formatter_.format(*it, ctx);
      |               ~~~~~~~~~~~~~~~~~^~~~~~
include/fmt/core.h:2709:22: note: candidate function template not viable: no known conversion from 'const std::filesystem::path' to 'const fmt::basic_string_view<char>' for 1st argument
 2709 |   FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const
      |                      ^
2 errors generated.

To Reproduce Compile against latest fmt

Expected behavior Should build cleanly.

Environment:

Additional Context I didn't open a PR, because I don't really know if this is a suitable fix, but the changes I made in the following diff allowed compilation, and the test suite was at least successful.

diff --git a/source/citnames/source/semantic/Semantic.cc b/source/citnames/source/semantic/Semantic.cc
index e956ecf..5730f25 100644
--- a/source/citnames/source/semantic/Semantic.cc
+++ b/source/citnames/source/semantic/Semantic.cc
@@ -87,11 +87,16 @@ namespace cs::semantic {
         return false;
     }

+
     std::ostream &Compile::operator<<(std::ostream &os) const {
+        std::vector<std::string> sources_str;
+        std::transform(sources.begin(), sources.end(), std::back_inserter(sources_str),
+                   [](const auto& path) { return path.string(); });
+
         os  << "Compile { working_dir: " << working_dir
             << ", compiler: " << compiler
             << ", flags: " << fmt::format("[{}]", fmt::join(flags.begin(), flags.end(), ", "))
-            << ", sources: " << fmt::format("[{}]", fmt::join(sources.begin(), sources.end(), ", "))
+            << ", sources: " << fmt::format("[{}]", fmt::join(sources_str.begin(), sources_str.end(), ", "))
             << ", output: " << (output ? output.value().string() : "")
             << " }";
         return os;
rizsotto commented 1 year ago

Thanks @EmmaJaneBonestell , will look at this issue next week.

rizsotto commented 1 year ago

I've made a version bump for the fmt library, and it seems to work just fine. (No compile error.)