Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build error when format boost::filesystem::path using 8.1.1 #2778

Closed
chengfzy opened this issue Feb 18, 2022 · 1 comment
Closed

build error when format boost::filesystem::path using 8.1.1 #2778

chengfzy opened this issue Feb 18, 2022 · 1 comment
Labels

Comments

@chengfzy
Copy link

chengfzy commented Feb 18, 2022

Building error for below code when using fmt 8.1.1, enen I add <fmt/ostream.h>

#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <boost/filesystem.hpp>
#include <iostream>

using namespace std;
using namespace fmt;

int main(int argc, char* argv[]) {
    boost::filesystem::path p("./data");
    cout << "print using cout, p = " << p << endl;  // OK
    cout << format("p = {}", p.string()) << endl;   // OK
    cout << format("p = {}", p) << endl;            // error
    return 0;
}

The output is:

[proc] Executing command: /usr/local/bin/cmake --build /home/jeffery/Documents/Code/Others/CppTemp/buildDebug --config Debug --target all -j 4 --
[build] [1/2  50% :: 1.667] Building CXX object CMakeFiles/CppTemp.dir/src/main.cpp.o
[build] FAILED: CMakeFiles/CppTemp.dir/src/main.cpp.o 
[build] /bin/x86_64-linux-gnu-g++-9 -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DFMT_HEADER_ONLY=1 -DGFLAGS_IS_A_DLL=0 -DGTEST_LINKED_AS_SHARED_LIBRARY=1 -DJSON_DIAGNOSTICS=0 -DJSON_USE_IMPLICIT_CONVERSIONS=1 -I../include -isystem /usr/local/include/eigen3 -isystem /usr/local/include/opencv4 -g -fPIE -std=gnu++17 -MD -MT CMakeFiles/CppTemp.dir/src/main.cpp.o -MF CMakeFiles/CppTemp.dir/src/main.cpp.o.d -o CMakeFiles/CppTemp.dir/src/main.cpp.o -c ../src/main.cpp
[build] In file included from /usr/local/include/fmt/format.h:48,
[build]                  from /usr/local/include/fmt/ostream.h:13,
[build]                  from ../src/main.cpp:1:
[build] /usr/local/include/fmt/core.h: In substitution of ‘template<bool B> using bool_constant = std::integral_constant<bool, __v> [with bool B = ((fmt::v8::detail::has_const_formatter<boost::filesystem::path, fmt::v8::basic_format_context<fmt::v8::appender, char> >() || (!(bool)std::integral_constant<bool, false>::value)) || ((bool)std::integral_constant<bool, true>::value))]’:
[build] /usr/local/include/fmt/core.h:1450:10:   required from ‘struct fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >::formattable<boost::filesystem::path, boost::filesystem::path>’
[build] /usr/local/include/fmt/core.h:1465:25:   required by substitution of ‘template<class T, typename std::enable_if<(! fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >::formattable<T, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value), int>::type <anonymous> > constexpr fmt::v8::detail::unformattable_const fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >::do_map<T, <enumerator> >(T&&) [with T = boost::filesystem::path; typename std::enable_if<(! fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >::formattable<T, typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value), int>::type <anonymous> = <missing>]’
[build] /usr/local/include/fmt/core.h:1476:33:   required by substitution of ‘template<class T, class U, typename std::enable_if<((((! fmt::v8::detail::is_string<U>::value) && (! fmt::v8::is_char<U>::value)) && (! std::is_array<_To>::value)) && (std::is_constructible<fmt::v8::formatter<U, char, void> >::value || std::is_constructible<fmt::v8::detail::fallback_formatter<U, char, void> >::value)), int>::type <anonymous> > constexpr decltype (((fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >*)this)->fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >::do_map(forward<T>(val))) fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender, char> >::map<T, U, <enumerator> >(T&&) [with T = boost::filesystem::path; U = boost::filesystem::path; typename std::enable_if<((((! fmt::v8::detail::is_string<U>::value) && (! fmt::v8::is_char<U>::value)) && (! std::is_array<_To>::value)) && (std::is_constructible<fmt::v8::formatter<U, char, void> >::value || std::is_constructible<fmt::v8::detail::fallback_formatter<U, char, void> >::value)), int>::type <anonymous> = 0]’
[build] /usr/local/include/fmt/core.h:1806:5:   required by substitution of ‘template<class FormatContext, class U, typename std::enable_if<std::is_same<U, const boost::filesystem::path>::value, int>::type <anonymous> > decltype (ctx.out()) fmt::v8::formatter<boost::filesystem::path, char, void>::format<FormatContext, U, <enumerator> >(U&, FormatContext&) [with FormatContext = fmt::v8::basic_format_context<fmt::v8::appender, char>; U = const boost::filesystem::path; typename std::enable_if<std::is_same<U, const boost::filesystem::path>::value, int>::type <anonymous> = 0]’
[build] /usr/local/include/fmt/core.h:730:72:   required by substitution of ‘template<class Context, class T> constexpr decltype ((typename Context::formatter_type<T>().format(declval<const T&>(), declval<Context&>()), true)) fmt::v8::detail::has_const_formatter_impl(T*) [with Context = fmt::v8::basic_format_context<fmt::v8::appender, char>; T = boost::filesystem::path]’
[build] /usr/local/include/fmt/core.h:740:43:   [ skipping 4 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
[build] /usr/local/include/fmt/core.h:1492:7:   required by substitution of ‘template<class T, class Context> using mapped_type_constant = fmt::v8::detail::type_constant<decltype (fmt::v8::detail::arg_mapper<Context>().map(declval<const T&>())), typename Context::char_type> [with T = boost::filesystem::path; Context = fmt::v8::basic_format_context<fmt::v8::appender, char>]’
[build] /usr/local/include/fmt/core.h:1688:10:   required from ‘constexpr long long unsigned int fmt::v8::detail::encode_types() [with Context = fmt::v8::basic_format_context<fmt::v8::appender, char>; Arg = boost::filesystem::path; Args = {}]’
[build] /usr/local/include/fmt/core.h:1840:58:   required from ‘constexpr const long long unsigned int fmt::v8::format_arg_store<fmt::v8::basic_format_context<fmt::v8::appender, char>, boost::filesystem::path>::desc’
[build] /usr/local/include/fmt/core.h:1954:45:   required from ‘constexpr fmt::v8::basic_format_args<Context>::basic_format_args(const fmt::v8::format_arg_store<Context, Args ...>&) [with Args = {boost::filesystem::path}; Context = fmt::v8::basic_format_context<fmt::v8::appender, char>]’
[build] /usr/local/include/fmt/core.h:3119:17:   required from ‘std::string fmt::v8::format(fmt::v8::format_string<T ...>, T&& ...) [with T = {boost::filesystem::path&}; std::string = std::__cxx11::basic_string<char>; fmt::v8::format_string<T ...> = fmt::v8::basic_format_string<char, boost::filesystem::path&>]’
[build] ../src/main.cpp:13:31:   required from here
[build] /usr/local/include/fmt/core.h:1451:54: error: ‘constexpr bool fmt::v8::detail::has_const_formatter() [with T = boost::filesystem::path; Context = fmt::v8::basic_format_context<fmt::v8::appender, char>]’ called in a constant expression before its definition is complete
[build]  1451 |       : bool_constant<has_const_formatter<U, Context>() ||
[build]       |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
[build] /usr/local/include/fmt/core.h:1452:68: note: in template argument for type ‘bool’
[build]  1451 |       : bool_constant<has_const_formatter<U, Context>() ||
[build]       |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~          
[build]  1452 |                       !std::is_const<remove_reference_t<T>>::value ||
[build]       |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
[build]  1453 |                       has_fallback_formatter<U, char_type>::value> {};
[build]       |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1
@vitaut
Copy link
Contributor

vitaut commented Feb 18, 2022

In a way this is addressed in the current master by requiring a formatter specialization for types with operator<< (https://godbolt.org/z/7sTz3Yo7W):

template <>
struct fmt::formatter<boost::filesystem::path> : ostream_formatter {};

It's a bit unfortunate that ostream formatting is broken for boost::filesystem::path but I don't think it's worth implementing a workaround considering that implicit ostream insertion operator support is going away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants