constexpr 使用 clang 编译 TensorFlow 时出错

Error in constexpr using clang to compile TensorFlow

本文关键字:出错 TensorFlow 编译 使用 clang constexpr      更新时间:2023-10-16

我正在尝试使用clang编译张量流, 并获得有关constexpr的以下错误

In file included from /tensorflow/tensorflow/lite/tools/make/downloads/absl/absl/time/clock.h:26:
/tensorflow/tensorflow/lite/tools/make/downloads/absl/absl/time/time.h:1404:55: error: constexpr function's 2nd parameter type 'std::ratio<60>' is not a literal type
constexpr Duration FromInt64(int64_t v, std::ratio<60>) {
~~~~~~~~~~~~~~^
/toolkit/include/usr/h/public/ratio:100:9: note: 'ratio<60, 1>' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors
struct ratio
^

这是相关的代码段:

template <std::intmax_t N>
constexpr Duration FromInt64(int64_t v, std::ratio<1, N>) {
static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio");
// Subsecond ratios cannot overflow.
return MakeNormalizedDuration(
v / N, v % N * kTicksPerNanosecond * 1000 * 1000 * 1000 / N);
}
constexpr Duration FromInt64(int64_t v, std::ratio<60>) {
return (v <= (std::numeric_limits<int64_t>::max)() / 60 &&
v >= (std::numeric_limits<int64_t>::min)() / 60)
? MakeDuration(v * 60)
: v > 0 ? InfiniteDuration() : -InfiniteDuration();
}

谢谢,如果有人能指出我正确的方向

它似乎在操场上为我工作

#include <ratio>
#include <iostream>
template <std::intmax_t N>
constexpr std::intmax_t FromInt64(int64_t v, std::ratio<1, N>) {
static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio");
return N;
}
constexpr std::intmax_t FromInt64(int64_t v, std::ratio<60>) {
return -100;
}
int main() {
auto a = FromInt64(5, std::ratio<1, 5>{});
std::cout << a << " "; // 5
auto b = FromInt64(5, std::ratio<60>{});
std::cout << b; // -100
}

很可能std::ratio尚未在该上下文中定义。如果std::ratio不完整,则代码将无法编译。也许尝试

#include <ratio> 

在编译该代码之前。