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

compile error when print user defined type with v1.10.0 or higher #2777

Closed
subenle-nreal opened this issue Jun 25, 2023 · 3 comments
Closed

Comments

@subenle-nreal
Copy link

subenle-nreal commented Jun 25, 2023

I want to print MyVector3f by by implementing operator<<, it works well with spdlog of version v1.9.2, but will get a compile error when upgrade to version v1.10.0. It seems that the class is_streamable in spdlog/fmt/bundled/ostream.h was changed in v1.10.0.

complie error:

enableif.cpp:25:11: error: no member named 'x' in 'fmt::basic_string_view<char>'
        v.x() = this->x;
        ~ ^
/spdlog/include/spdlog/fmt/bundled/core.h:1373:41: note: in instantiation of function template specialization 'MyVector3f::operator basic_string_view<fmt::basic_string_view<char>>' requested here
    return basic_string_view<char_type>(val);
                                        ^
/spdlog/include/spdlog/logger.h:90:9: note: in instantiation of function template specialization 'spdlog::logger::log_<MyVector3f &>' requested here
        log_(loc, lvl, fmt, std::forward<Args>(args)...);
        ^
/spdlog/include/spdlog/logger.h:96:9: note: in instantiation of function template specialization 'spdlog::logger::log<MyVector3f &>' requested here
        log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
        ^
/spdlog/include/spdlog/logger.h:158:9: note: in instantiation of function template specialization 'spdlog::logger::log<MyVector3f &>' requested here
        log(level::info, fmt, std::forward<Args>(args)...);
        ^
/spdlog/include/spdlog/spdlog.h:157:27: note: in instantiation of function template specialization 'spdlog::logger::info<MyVector3f &>' requested here
    default_logger_raw()->info(fmt, std::forward<Args>(args)...);
                          ^
enableif.cpp:41:13: note: in instantiation of function template specialization 'spdlog::info<MyVector3f &>' requested here
    spdlog::info("v3 {}", v3);
            ^
enableif.cpp:26:11: error: no member named 'y' in 'fmt::basic_string_view<char>'
        v.y() = this->y;
        ~ ^
enableif.cpp:27:11: error: no member named 'z' in 'fmt::basic_string_view<char>'
        v.z() = this->z;
        ~ ^
3 errors generated.

code is list below:

#include <iostream>
#include <type_traits>
#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
using namespace std;

class MyVector3f {
   public:
    float x = 1;
    float y = 2;
    float z = 3;

   public:
    MyVector3f() {}
    template <typename LocalType>
    MyVector3f(const LocalType& v) {
        this->x = v.x();
        this->y = v.y();
        this->z = v.z();
    }

    template <typename LocalType>
    operator LocalType() const {
        LocalType v;
        v.x() = this->x;
        v.y() = this->y;
        v.z() = this->z;
        return v;
    }

    template <typename OStream>
    friend OStream& operator<<(OStream& os, const MyVector3f& v) {
        return os << "["
                  << " x:" << v.x << ", y:" << v.y << ", z:" << v.z << "]";
    }
};

int main()
{
    MyVector3f v3;
    spdlog::info("v3 {}", v3);
    return 0;
}
@tt4g
Copy link
Contributor

tt4g commented Jun 25, 2023

Due to specification change in fmt library.
See fmtlib/fmt#3465, fmtlib/fmt#2357

@subenle-nreal
Copy link
Author

Due to specification change in fmt library. See #3465, #2357

thanks, I've confirmed that the issue was introduced in fmt version 8.1.1.

@tt4g
Copy link
Contributor

tt4g commented Jun 26, 2023

Due to specification change in fmt library. See #3465, #2357

Oops. I'm forgot fmtlib/fmt prefix.
Comment updated.

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