Skip to content

Custom pointer formatter is invalid after fmt 9.0. #4037

@Minavery

Description

@Minavery

I find my old code is invalid when using fmt 10.2.1.

'''
template<>
struct fmt::formatter<float > : formatter<string_view> {
auto format(float
pointer, fmt::format_context& ctx) const {
if (pointer != nullptr) {
auto&& str = fmt::format("{}={}", (void)pointer, *pointer);
return formatterfmt::string_view::format(str, ctx); }
else {
return formatterfmt::string_view::format("nullptr", ctx);
}
}
};

int main() {
float a = 0.0;
fmt::print("{}\n",&a);
}
'''

error is "Formatting of non-void pointer is disallowed."

Compiler Explorer Code.cpp.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions