fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
19.84k stars 2.42k forks source link

inclusion of fmt/format-inl.h header causes compile fault (regression after 10.2.1) #3969

Closed grooverdan closed 1 month ago

grooverdan commented 1 month ago

Bisected to d70729215fba1d54862e407b626abf86ddf409bf the inclusion of the generated compile header fails include/fmt/format-inl.h

Our code: https://github.com/MariaDB/server/blob/mariadb-10.11.8/sql/item_strfunc.cc#L61

removing the following didn't solve the compile problem:

#define FMT_STATIC_THOUSANDS_SEPARATOR ','
#define FMT_HEADER_ONLY 1
$ cmake --build . --target sql
[1/2] Building CXX object sql/CMakeFiles/sql.dir/item_strfunc.cc.o
FAILED: sql/CMakeFiles/sql.dir/item_strfunc.cc.o 
/usr/lib64/ccache/clang++ -DHAVE_CONFIG_H -DHAVE_EVENT_SCHEDULER -DHAVE_POOL_OF_THREADS -DMYSQL_SERVER -D_FILE_OFFSET_BITS=64 -I/home/dan/repos/mariadb-server-10.11/wsrep-lib/include -I/home/dan/repos/mariadb-server-10.11/wsrep-lib/wsrep-API/v26 -I/home/dan/repos/build-mariadb-server-10.11/include -I/home/dan/repos/mariadb-server-10.11/include/providers -I/home/dan/repos/mariadb-server-10.11/include -I/home/dan/repos/mariadb-server-10.11/sql -I/home/dan/repos/build-mariadb-server-10.11/sql -I/home/dan/repos/mariadb-server-10.11/tpool -I/home/dan/repos/inst-fmt/include -fstack-protector --param=ssp-buffer-size=4 -O2 -g -DNDEBUG -fno-omit-frame-pointer -D_FORTIFY_SOURCE=2 -DDBUG_OFF -Wall -Wdeclaration-after-statement -Wenum-compare -Wenum-conversion -Wextra -Wformat-security -Wmissing-braces -Wno-init-self -Wno-null-conversion -Wno-unused-parameter -Wno-unused-private-field -Woverloaded-virtual -Wnon-virtual-dtor -Wvla -Wwrite-strings -std=gnu++11   -DHAVE_OPENSSL -DOPENSSL_API_COMPAT=0x10100000L -MD -MT sql/CMakeFiles/sql.dir/item_strfunc.cc.o -MF sql/CMakeFiles/sql.dir/item_strfunc.cc.o.d -o sql/CMakeFiles/sql.dir/item_strfunc.cc.o -c /home/dan/repos/mariadb-server-10.11/sql/item_strfunc.cc
In file included from /home/dan/repos/mariadb-server-10.11/sql/item_strfunc.cc:61:
In file included from /home/dan/repos/inst-fmt/include/fmt/format-inl.h:25:
In file included from /home/dan/repos/inst-fmt/include/fmt/format.h:54:
/home/dan/repos/inst-fmt/include/fmt/base.h:1338:23: error: no matching member function for call to 'format'
 1338 |     ctx.advance_to(cf.format(*static_cast<qualified_type*>(arg), ctx));
      |                    ~~~^~~~~~
/home/dan/repos/inst-fmt/include/fmt/base.h:1319:21: note: in instantiation of function template specialization 'fmt::detail::value<fmt::context>::format_custom_arg<String, fmt::formatter<String>>' requested here
 1319 |     custom.format = format_custom_arg<
      |                     ^
/home/dan/repos/inst-fmt/include/fmt/base.h:1575:10: note: in instantiation of function template specialization 'fmt::detail::value<fmt::context>::value<String>' requested here
 1575 |   return {arg_mapper<Context>().map(val)};
      |          ^
/home/dan/repos/inst-fmt/include/fmt/base.h:1582:16: note: in instantiation of function template specialization 'fmt::detail::make_arg<true, fmt::context, String, 0>' requested here
 1582 |   arg.value_ = make_arg<true, Context>(val);
      |                ^
/home/dan/repos/mariadb-server-10.11/sql/item_strfunc.cc:1461:35: note: in instantiation of function template specialization 'fmt::detail::make_arg<fmt::context, String>' requested here
 1461 |       vargs[carg-1]= fmt::detail::make_arg<ctx>(*parg);
      |                                   ^
/home/dan/repos/mariadb-server-10.11/sql/item_strfunc.cc:1385:10: note: candidate function template not viable: 'this' argument has type 'const fmt::formatter<String>', but method is not marked const
 1385 |     auto format(String c, FormatContext& ctx) -> decltype(ctx.out()) {
      |          ^
1 error generated.
ninja: build stopped: subcommand failed.
$ /usr/lib64/ccache/clang++ --version
clang version 17.0.6 (Fedora 17.0.6-2.fc39)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
grooverdan commented 1 month ago

nm - our problem

diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 19e011d54f8..28d7ee71453 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1382,7 +1382,7 @@ bool Item_func_sformat::fix_length_and_dec(THD *thd)
 namespace fmt {
   template <> struct formatter<String>: formatter<string_view> {
     template <typename FormatContext>
-    auto format(String c, FormatContext& ctx) -> decltype(ctx.out()) {
+    auto format(String c, FormatContext& ctx) const -> decltype(ctx.out()) {
       string_view name = { c.ptr(), c.length() };
       return formatter<string_view>::format(name, ctx);
     };