【问题标题】:C++20 <chrono> incomplete type used in nested name specifierC++20 <chrono> 嵌套名称说明符中使用的不完整类型
【发布时间】:2021-07-25 10:20:56
【问题描述】:

现在支持new calendar and time zone featuresGCC 11 已发布,我正在尝试在我的代码中使用这些。

使用以下最小示例:

#include <chrono>
#include <iostream>

int main()
{
    using namespace std;

    cout << chrono::utc_clock::now() << endl;

    return EXIT_SUCCESS;
}

使用以下代码编译:

> /usr/local/gcc-11.1.0/bin/g++-11.1 -std=c++-20 main.cpp

给出以下错误:

main.cpp: In function ‘int main()’:
main.cpp:8:36: error: incomplete type ‘std::chrono::utc_clock’ used in 
    nested name specifier
    8 |         cout << chrono::utc_clock::now() << endl;
      | 

我已经调查过这个错误,它似乎通常源于前向声明。有谁知道为什么会这样?

我也尝试过显式链接新构建的 GCC 11 版本的 libstdc++.a:

/usr/local/gcc-11.1.0/bin/g++-11.1 -std=c++20 -L/usr/local/gcc-11.1.0/lib -lstdc++ main.cpp

但是我得到了同样的错误信息。

一些额外的信息:

> /usr/local/gcc-11.1.0/bin/g++-11.1 --version

给出以下输出:

g++-11.1 (GCC) 12.0.0 20210427 (experimental)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

这出乎我的意料,因为我期待看到 11.1。我在 MacOS 上构建了这个,我的 clang++ 版本是 12.0.5。这是预期的吗?这可能是问题的潜在根源吗?

此外,this website 显示编译器对 C++20 标准库功能的支持表明 GCC 11部分支持更新后的chrono

最后,我使用this video 作为参考从源代码构建了 GCC 11。

【问题讨论】:

  • 据我了解,目前还没有编译器完全支持 C++20; Visual Studio 2022 在编译器和 Intellisense 都支持之前不会发布,即使编译器首先兼容。

标签: c++ gcc c++20 chrono libstdc++


【解决方案1】:

此时 gcc 中只有部分 C++20 计时支持。 Here is the current state of the libstdc++ source code on this matter. 这显示了utc_clock 的简单前向声明,并且没有定义,这与您看到的错误消息一致。

am看到对file_clock 的更多支持,包括在file_clock::time_pointsystem_clock::time_point 之间转换的低级API。这是一个重要的补充。

此外,我还看到了对 calendrical types in C++20(例如 year_month_day 等)的支持,这就是发行说明所指的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多