【问题标题】:Prevent fmt from printing function pointers防止 fmt 打印函数指针
【发布时间】:2022-01-01 06:04:38
【问题描述】:

我有一辆马车program。逻辑是废话,只是一个玩具例子。

#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>);
} 

输出是

浮点大小为 4 个字节:true
双倍大小为 4 个字节:true

问题是我将函数指针传递给fmt::format 并将其打印为布尔值。修复很简单,直接调用函数就好了,不知道有没有办法捕捉到这样的bug。

由于函数返回bool,它实际上看起来是合理的输出。

【问题讨论】:

    标签: c++ c++20 fmt


    【解决方案1】:

    这是由指针检测逻辑未捕获的函数指针引起的错误。我打开了一个 GitHub 问题:https://github.com/fmtlib/fmt/issues/2609。

    更新:问题已修复。

    【讨论】:

      猜你喜欢
      • 2020-06-21
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多