Prevent fmt from printing function pointers

Viewed 517

I have a following buggy program. Logic is nonsense, it is just a toy example.

#include <ranges>
#include <iostream>
#include <fmt/format.h>
#include <fmt/ranges.h>

template<typename T>
constexpr bool size_is_4(){
    return sizeof(T)==4;
}

int main() {
    std::cout << fmt::format("float size is 4 bytes  : {}\n", size_is_4<float>);
    std::cout << fmt::format("double size is 4 bytes : {}\n", size_is_4<double>);
} 

output is

float size is 4 bytes : true
double size is 4 bytes : true

The problem is that I pass a function pointer to fmt::format and it prints it out as a boolean. Fix is easy, just invoke the function, but I wonder if there is a way to catch bugs like this.

Since function returns bool it actually looks reasonable as output.

1 Answers
Related