Sophus icon indicating copy to clipboard operation
Sophus copied to clipboard

`static_assert` failure when used with fmt 9.0.0+

Open carlocab opened this issue 1 year ago • 1 comments

Describe the bug Using Sophus with fmt 9.0.0+ produces the following error:

  In file included from /tmp/sophus-test-20220724-36730-72obh/HelloSO3.cpp:2:
  In file included from /opt/homebrew/include/sophus/geometry.hpp:6:
  In file included from /opt/homebrew/include/sophus/se2.hpp:6:
  In file included from /opt/homebrew/include/sophus/so2.hpp:12:
  In file included from /opt/homebrew/include/sophus/rotation_matrix.hpp:9:
  In file included from /opt/homebrew/include/sophus/types.hpp:7:
  In file included from /opt/homebrew/include/sophus/common.hpp:35:
  In file included from /opt/homebrew/include/fmt/format.h:48:
  /opt/homebrew/include/fmt/core.h:1732:3: error: static_assert failed due to requirement 'formattable' "Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt"
    static_assert(
    ^

To Reproduce Install fmt 9.0.0, and then try to use Sophus. For example, the following makes use of HelloSO3.cpp:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(HelloSO3)
find_package(Sophus REQUIRED)
add_executable(HelloSO3 HelloSO3.cpp)
target_link_libraries(HelloSO3 Sophus::Sophus)

Running the above CMakeLists.txt with HelloSO3.cpp in your current working directory with cmake . && make produces the error shown above.

Expected behavior No error.

Sophus version: 4ac843dd9050a5d175e5c0a857da9315fbc436f0

I haven't found time to test on HEAD yet, but the changes to the files in the call stack since this commit hash don't look to have fixed the issue.

Additional context

So far I've reproduced this on macOS 11 with Apple-provided Clang, but I don't think this is specific to that.

carlocab avatar Jul 24 '22 15:07 carlocab

Same issue. I define SOPHUS_USE_BASIC_LOGGING before include sophus header to disable fmt temporarily.

LiuPeiqiCN avatar Aug 08 '22 02:08 LiuPeiqiCN

yeah, fmt 9.0.0 seems broken. https://github.com/fmtlib/fmt/issues/2936

I suggest to revert to 8.1.1 or try HEAD of master: https://github.com/fmtlib/fmt/

strasdat avatar Aug 18 '22 04:08 strasdat

From the 9.0.0 release notes, this item seem like it might be the cause for the error. It sounds like that won't go away with future fmt versions, so at some point Sophus should adapt to it (ideally while staying compatible to older versions of fmt).

Disabled automatic std::ostream insertion operator (operator<<) discovery when fmt/ostream.h is included to prevent ODR violations. You can get the old behavior by defining FMT_DEPRECATED_OSTREAM but this will be removed in the next major release. Use fmt::streamed or fmt::ostream_formatter to enable formatting via std::ostream instead.

To test one could define FMT_DEPRECATED_OSTREAM, but that would just be a temporary workaround.

NikolausDemmel avatar Aug 27 '22 11:08 NikolausDemmel

For future reference, this was fixed in https://github.com/strasdat/Sophus/pull/376. (At the very least, this is fixed in the latest version of Sophus.)

carlocab avatar Oct 13 '22 02:10 carlocab