Skip to content

Can't run clang-tidy on 12.0 #4552

@olavsr

Description

@olavsr

Hi!

I'm trying to upgrade fmt from 11.2.0 to 12.0 in our codebase. This made clang-tidy fail on files that include fmt/std.h, not due to warnings as those are disabled for "external" code, it actually just fails to run. I get the following output (anonymized a bit as this is from a corporate codebase):

FAILED: /workspaces/env/libs/.../file.cpp.o 
/usr/bin/cmake -E __run_co_compile --launcher=ccache --tidy="clang-tidy-19;-warnings-as-errors=-*;--format-style=file;--extra-arg-before=--driver-mode=g++;--export-fixes=/workspaces/env/libs/.../file.cpp.o.yaml" --source=/workspaces/env/libs/.../file.cpp -- /usr/bin/g++-10 ... -isystem /workspaces/env/extern/fmt/fmt/include -isystem /workspaces/env/extern/spdlog/spdlog/include ... -march=x86-64-v3 -mtune=skylake -O3 -DNDEBUG -g -std=c++2a -fPIC -Werror -Wall -Wextra -Wpedantic -Wformat=2 -Wfloat-equal -Wnull-dereference -Wshadow -Wconversion -Wsign-conversion -Wcast-align -Woverloaded-virtual -Wmisleading-indentation -Wnon-virtual-dtor -Wold-style-cast -Wlogical-op -Wtrampolines -Wduplicated-cond -Wduplicated-branches -Wuseless-cast -pthread -MD -MT /workspaces/env/libs/.../file.cpp.o -MF /workspaces/env/libs/.../file.cpp.od -o /workspaces/env/libs/.../file.cpp.o -c /workspaces/env/libs/.../file.cpp
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:2295:45: error: implicit instantiation of undefined template 'fmt::detail::type_is_unformattable_for<std::filesystem::path, char>' [clang-diagnostic-error]
 2295 |     type_is_unformattable_for<T, char_type> _;
      |                                             ^
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:2268:44: note: in instantiation of function template specialization 'fmt::detail::value<fmt::context>::value<std::filesystem::path, 0>' requested here
 2268 |   FMT_CONSTEXPR20 FMT_INLINE value(T& x) : value(x, custom_tag()) {}
      |                                            ^
/workspaces/env/extern/fmt/fmt/include/fmt/format.h:4349:40: note: in instantiation of function template specialization 'fmt::detail::value<fmt::context>::value<const std::filesystem::path, 0>' requested here
 4349 |   return vformat(fmt.str, vargs<T...>{{args...}});
      |                                        ^
/workspaces/env/extern/fmt/fmt/include/fmt/std.h:263:17: note: in instantiation of function template specialization 'fmt::format<const std::filesystem::path &>' requested here
  263 |     return fmt::format(FMT_STRING("{}"), base);
      |                 ^
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:2135:45: note: template is declared here
 2135 | template <typename T, typename Char> struct type_is_unformattable_for;
      |                                             ^
/workspaces/env/extern/fmt/fmt/include/fmt/std.h:269:35: error: call to consteval function 'fmt::fstring<const std::filesystem::path &>::fstring<5UL>' is not a constant expression [clang-diagnostic-error]
  269 |     return fmt::format(FMT_STRING("{:g}"), base);
      |                                   ^
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:1757:5: note: non-constexpr function 'report_error' cannot be used in a constant expression
 1757 |     report_error(message);
      |     ^
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:1641:12: note: in call to 'handler.on_error(&"unknown format specifier"[0])'
 1641 |     return handler.on_error("unknown format specifier"), end;
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:1654:19: note: in call to 'parse_replacement_field<char, fmt::detail::format_string_checker<char, 1, 0, false> &>(&"{:g}"[2], &"{:g}"[4], checker(s, arg_pack()))'
 1654 |       begin = p = parse_replacement_field(p - 1, end, handler);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:2744:28: note: in call to 'parse_format_string<char, fmt::detail::format_string_checker<char, 1, 0, false>>({&"{:g}"[0], 4}, checker(s, arg_pack()))'
 2744 |     if (FMT_USE_CONSTEVAL) parse_format_string<char>(s, checker(s, arg_pack()));
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/workspaces/env/extern/fmt/fmt/include/fmt/std.h:269:35: note: in call to 'fstring<5UL>("{:g}")'
  269 |     return fmt::format(FMT_STRING("{:g}"), base);
      |                                   ^
/workspaces/env/extern/fmt/fmt/include/fmt/format.h:4251:39: note: expanded from macro 'FMT_STRING'
 4251 | #define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string)
      |                                       ^
/workspaces/env/extern/fmt/fmt/include/fmt/format.h:4223:36: note: expanded from macro 'FMT_STRING_IMPL'
 4223 | #  define FMT_STRING_IMPL(s, base) s
      |                                    ^
/workspaces/env/extern/fmt/fmt/include/fmt/base.h:656:27: note: declared here
  656 | FMT_NORETURN FMT_API void report_error(const char* message);
      |                           ^
13692 warnings and 2 errors generated.
Error while processing /workspaces/env/libs/.../file.cpp.
Suppressed 13705 warnings (13692 in non-user code, 13 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
ninja: build stopped: subcommand failed.

We use clang-tidy-19, but I tried with clang-tidy-21 as well which fails in the same way. We invoke clang-tidy through CMake, there could to be some interaction there as I cannot recreate the issue when running clang-tidy-19 by itself. The changes in 619b3a5 introduced these issues for us. Reverting that commit, or just setting FMT_CLANG_ANALYZER=0 for both cases in fmt/format.h fixes the issue. Setting FMT_CPP_LIB_FILESYSTEM=0 also works as a workaround. Is something broken here or are we just doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions