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.
This is a bug caused by function pointers not caught by the pointer detection logic. I opened a GitHub issue: https://github.com/fmtlib/fmt/issues/2609.
Update: the issue has been fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With