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

Multiple errors on gcc 8.2/8.3 #1957

Closed
phprus opened this issue Oct 26, 2020 · 3 comments
Closed

Multiple errors on gcc 8.2/8.3 #1957

phprus opened this issue Oct 26, 2020 · 3 comments

Comments

@phprus
Copy link
Contributor

phprus commented Oct 26, 2020

gcc: 8.2.1
os: openSUSE 15.1

First of error:

[ 21%] Building CXX object test/CMakeFiles/locale-test.dir/locale-test.cc.o
/home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc: In member function ‘virtual void LocaleTest_Format_Test::TestBody()’:
/home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc:59:61: error: no matching function for call to ‘format_to(std::back_insert_iterator<std::__cxx11::basic_string<char> >, std::locale&, const char [5], int)’
   fmt::format_to(std::back_inserter(s), loc, "{:L}", 1234567);
                                                             ^
In file included from /home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/format.h:44,
                 from /home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/locale.h:13,
                 from /home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc:8:
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/core.h:1994:13: note: candidate: ‘template<class OutputIt, class S, class ... Args, bool enable> typename std::enable_if<enable, OutputIt>::type fmt::v7::format_to(OutputIt, const S&, Args&& ...)’
 inline auto format_to(OutputIt out, const S& format_str, Args&&... args) ->
             ^~~~~~~~~
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/core.h:1994:13: note:   template argument deduction/substitution failed:
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/core.h:1993:74: error: no type named ‘type’ in ‘struct fmt::v7::detail::char_t_impl<std::locale, void>’
           bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
                                                                          ^~~~~
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/core.h:1993:74: error: could not convert template argument ‘<expression error>’ from ‘<type error>’ to ‘bool’
In file included from /home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/locale.h:13,
                 from /home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc:8:
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/format.h:3822:48: note: candidate: ‘template<class S, class ... Args, long unsigned int SIZE, class Char> typename fmt::v7::buffer_context<Char>::iterator fmt::v7::format_to(fmt::v7::basic_memory_buffer<Char, SIZE>&, const S&, Args&& ...)’
 inline typename buffer_context<Char>::iterator format_to(
                                                ^~~~~~~~~
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/format.h:3822:48: note:   template argument deduction/substitution failed:
/home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc:59:61: note:   ‘std::back_insert_iterator<std::__cxx11::basic_string<char> >’ is not derived from ‘fmt::v7::basic_memory_buffer<Char, SIZE>’
   fmt::format_to(std::back_inserter(s), loc, "{:L}", 1234567);
                                                             ^
In file included from /home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc:8:
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/locale.h:56:17: note: candidate: ‘template<class OutputIt, class S, class ... Args, class Char, typename std::enable_if<fmt::v7::detail::is_output_iterator<OutputIt, Char>::value, int>::type <anonymous> > OutputIt fmt::v7::format_to(OutputIt, const std::locale&, const S&, Args&& ...)’
 inline OutputIt format_to(OutputIt out, const std::locale& loc,
                 ^~~~~~~~~
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/locale.h:56:17: note:   template argument deduction/substitution failed:
In file included from /home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/format.h:44,
                 from /home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/locale.h:13,
                 from /home/phprus/tmp/fmt/fmt-7.1.0/test/locale-test.cc:8:
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/core.h:277:62: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
 #define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
                                                              ^
/home/phprus/tmp/fmt/fmt-7.1.0/include/fmt/locale.h:55:11: note: in expansion of macro ‘FMT_ENABLE_IF’
           FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
           ^~~~~~~~~~~~~
@vitaut
Copy link
Contributor

vitaut commented Oct 26, 2020

Looks like the same gcc 8 bug as in #1949.

@phprus
Copy link
Contributor Author

phprus commented Oct 26, 2020

Yes...
Possible patch:

Index: fmt/include/fmt/locale.h
===================================================================
--- fmt.orig/include/fmt/locale.h
+++ fmt/include/fmt/locale.h
@@ -51,10 +51,10 @@ inline OutputIt vformat_to(
 }
 
 template <typename OutputIt, typename S, typename... Args,
-          typename Char = char_t<S>,
-          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
-inline OutputIt format_to(OutputIt out, const std::locale& loc,
-                          const S& format_str, Args&&... args) {
+          bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
+inline auto format_to(OutputIt out, const std::locale& loc,
+                          const S& format_str, Args&&... args) ->
+    typename std::enable_if<enable, OutputIt>::type {
   const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
   return vformat_to(out, loc, to_string_view(format_str), vargs);
 }
Index: fmt/include/fmt/core.h
===================================================================
--- fmt.orig/include/fmt/core.h
+++ fmt/include/fmt/core.h
@@ -1968,10 +1968,11 @@ inline void vprint_mojibake(std::FILE*, 
 // GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with
 // vformat_to<ArgFormatter>(...) overload, so SFINAE on iterator type instead.
 template <typename OutputIt, typename S, typename Char = char_t<S>,
-          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
-OutputIt vformat_to(
+          bool enable = detail::is_output_iterator<OutputIt, Char>::value>
+auto vformat_to(
     OutputIt out, const S& format_str,
-    basic_format_args<buffer_context<type_identity_t<Char>>> args) {
+    basic_format_args<buffer_context<type_identity_t<Char>>> args) ->
+    typename std::enable_if<enable, OutputIt>::type {
   decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
   detail::vformat_to(buf, to_string_view(format_str), args);
   return detail::get_iterator(buf);
@@ -2023,10 +2024,11 @@ inline format_to_n_result<OutputIt> vfor
  \endrst
  */
 template <typename OutputIt, typename S, typename... Args,
-          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char_t<S>>::value)>
-inline format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
+          bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
+inline auto format_to_n(OutputIt out, size_t n,
                                                 const S& format_str,
-                                                const Args&... args) {
+                                                const Args&... args) ->
+    typename std::enable_if<enable, format_to_n_result<OutputIt>>::type {
   const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
   return vformat_to_n(out, n, to_string_view(format_str), vargs);
 }
Index: fmt/include/fmt/color.h
===================================================================
--- fmt.orig/include/fmt/color.h
+++ fmt/include/fmt/color.h
@@ -589,10 +589,11 @@ OutputIt vformat_to(
   \endrst
 */
 template <typename OutputIt, typename S, typename... Args,
-          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char_t<S>>::value&&
+          bool enable = (detail::is_output_iterator<OutputIt, char_t<S>>::value&&
                             detail::is_string<S>::value)>
-inline OutputIt format_to(OutputIt out, const text_style& ts,
-                          const S& format_str, Args&&... args) {
+inline auto format_to(OutputIt out, const text_style& ts,
+                          const S& format_str, Args&&... args) ->
+    typename std::enable_if<enable, OutputIt>::type {
   return vformat_to(out, ts, to_string_view(format_str),
                     fmt::make_args_checked<Args...>(format_str, args...));
 }
Index: fmt/include/fmt/compile.h
===================================================================
--- fmt.orig/include/fmt/compile.h
+++ fmt/include/fmt/compile.h
@@ -667,14 +667,15 @@ OutputIt format_to(OutputIt out, const S
   return format_to(out, compiled, args...);
 }
 
-template <typename OutputIt, typename CompiledFormat, typename... Args,
-          FMT_ENABLE_IF(detail::is_output_iterator<
-                        OutputIt, typename CompiledFormat::char_type>::value&&
-                            std::is_base_of<detail::basic_compiled_format,
-                                            CompiledFormat>::value)>
-format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
-                                         const CompiledFormat& cf,
-                                         const Args&... args) {
+template <typename OutputIt, typename CompiledFormat, typename... Args>
+typename std::enable_if<(detail::is_output_iterator<
+                         OutputIt, typename CompiledFormat::char_type>::value&&
+                             std::is_base_of<detail::basic_compiled_format,
+                                             CompiledFormat>::value),
+                        format_to_n_result<OutputIt>
+>::type format_to_n(OutputIt out, size_t n,
+                    const CompiledFormat& cf,
+                    const Args&... args) {
   auto it =
       format_to(detail::truncating_iterator<OutputIt>(out, n), cf, args...);
   return {it.base(), it.count()};

@vitaut
Copy link
Contributor

vitaut commented Oct 26, 2020

Could you submit a PR?

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

No branches or pull requests

2 participants