c++c++11c++17g++fmt

When compiling {fmt} include file in Linux with g++ compiler getting an error of class is private and cannot be accessed from outside


I am using #include <fmt/ranges.h> to format std::array in my C++ application

#include <fmt/ranges.h>

#include <array>

int main()
{
    std::array<short unsigned int, 3> arr = {1, 2, 3};
    fmt::print("{}", arr);
}

It is properly compiling in windows and macos but failing in linux with g++ compiler with the below errors:

../externals/fmtlib/fmt/ranges.h:49:29: error: all member functions in class 'fmt::v10::detail::is_std_string_like' are private [-Werror=ctor-dtor-privacy] template class is_std_string_like {

../externals/fmtlib/fmt/ranges.h:65:29: error: all member functions in class 'fmt::v10::detail::is_map' are private [-Werror=ctor-dtor-privacy]

template class is_map {

../externals/fmtlib/fmt/ranges.h:49:29: error: all member functions in class 'fmt::v10::detail::is_std_string_like' are private [-Werror=ctor-dtor-privacy] template class is_std_string_like {

../externals/fmtlib/fmt/ranges.h:65:29: error: all member functions in class 'fmt::v10::detail::is_map' are private [-Werror=ctor-dtor-privacy]

template class is_map {

As of the time of writing, MSVC and Clang are the only 2 compilers supporting the header. Is it not supported with g++

It seems that MSVC and Clang are the only 2 compilers supporting this header <fmt/ranges.h>. And g++ is not supporting this header.

Please help me.


Solution

  • The problem is that you are opting into -Werror=ctor-dtor-privacy which rejects valid C++ code and the solution is to remove this flag from your build flags, at least when compiling fmt/ranges.h.