gpt4 book ai didi

c++ - gcc 4.9.2 -Wmissing-field-initializers 中的错误?

转载 作者:行者123 更新时间:2023-11-30 03:55:10 55 4
gpt4 key购买 nike

我在这段代码中遇到问题 - 可以将其 1:1 复制到 cpp 文件中以测试行为:

#include <atomic>

typedef struct
{
char sDateTime [20];
char sLogFileDirectory [300];
char sLogFileNameTemplate [300];
char sLogOutput [10][100];
std::atomic<bool> bReadyToFlush;
} LogEntries;

typedef struct
{
LogEntries leLogEntries [1] {};
} LogThreads;

使用 gcc 4.9.2 SLES 11 SP2 编译 g++ -std=c++11 gcc-warning-bug.cpp -Wall -Wextra -c我收到这些非常奇怪的警告:

gcc-warning-bug.cpp:18:34: warning: missing initializer for member ‘LogEntries::sDateTime’ [-Wmissing-field-initializers]
LogEntries leLogEntries [1] {};
^
gcc-warning-bug.cpp:18:34: warning: missing initializer for member ‘LogEntries::sLogFileDirectory’ [-Wmissing-field-initializers]
gcc-warning-bug.cpp:18:34: warning: missing initializer for member ‘LogEntries::sLogFileNameTemplate’ [-Wmissing-field-initializers]
gcc-warning-bug.cpp:18:34: warning: missing initializer for member ‘LogEntries::sLogOutput’ [-Wmissing-field-initializers]
gcc-warning-bug.cpp:18:34: warning: missing initializer for member ‘LogEntries::bReadyToFlush’ [-Wmissing-field-initializers]

添加 {}此行中的初始值设定项

std::atomic<bool>   bReadyToFlush {};

即使是 g++ 也在关于 LogEntries::sDateTime 的第一个警告中提示然后警告就消失了。

当我删除 std::atomic<bool> 时警告也消失了线。代码很简单;当你有 g++ 4.9.2 时检查一下 - 它真的很奇怪。

编辑:无论LogEntries struct成员我添加了{}初始化警告消失了。

如何解释这种行为?对我来说这是一个错误...

附言:我认为这是一个错误:将此行中的数组说明符更改为 1000:

    LogEntries              leLogEntries [1000] {};

g++ 将产生 5'000 个警告!我认为对每个数组值重复警告没有意义。

最佳答案

更新:

第一种情况现在已被 GNU 确认这是一个错误,但已在 gcc 5.0 中修复

ICE [内部编译器错误] 现在在错误数据库中 GNU bug database

这似乎是一个错误。我现在玩了一下,在修改后得到编译器消息 gcc 由于内部错误而停止。

更新: 根据要求,gcc 无法编译的代码。编译器选项:g++ -std=c++11 gcc-warning-bug.cpp -Wall -Wextra -Werror -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -c -有一些选项是因为 GNU 要求它提供错误报告。

#include <atomic>

class LogEntries
{
public:
char sDateTime [20];
std::atomic<bool> bReadyToFlush;
};

class LogThreads
{
public:
static LogEntries leLogEntries [10];
};

LogEntries LogThreads::leLogEntries [10] {};

编译器失败,输出如下:

gcc-warning-bug.cpp:16:43: internal compiler error: in gimplify_init_constructor, at gimplify.c:4007
....
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

我会准备示例代码并提交给开发团队。在我的项目中,成员 leLogEntries 是静态的。

当您删除 std::atomic 行时,它会起作用 --> std::atomic 实现中有问题吗?

关于c++ - gcc 4.9.2 -Wmissing-field-initializers 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29184431/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com