gcc 4.9.2 bug in -Wmissing-field-initializers? [英] gcc 4.9.2 bug in -Wmissing-field-initializers?

查看:4309
本文介绍了gcc 4.9.2 bug in -Wmissing-field-initializers?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题在这段代码 - 可以复制1:1到一个cpp文件为了测试的行为:

I have an issue in this code - which can be copied 1:1 into a cpp file in order to test the behaving:

#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 我收到这些非常奇怪的警告:

Compiling with gcc 4.9.2 SLES 11 SP2 g++ -std=c++11 gcc-warning-bug.cpp -Wall -Wextra -c I receive these very strange warnings:

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]

在此行中添加 {} / p>

Adding the {} initializer in this line

std::atomic<bool>   bReadyToFlush {};

甚至g ++在第一个警告中抱怨 LogEntries :: sDateTime 然后警告消失。

even g++ is complaining in the 1st warning about LogEntries::sDateTime then the warnings are gone.

当我删除 std :: atomic< bool> code>行。代码很简单;当你有g ++ 4.9.2检查出来 - 这真的很奇怪。

The warning is also gone when I remove the std::atomic<bool> line. The code is very simple; when you have g++ 4.9.2 check it out - it is really very strange.

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

Regardless to which LogEntries struct member I add the {} initializer the warnings are gone.

可以这个行为解释吗?对我来说,这是一个错误...

How can be this behaving explained? For me it is a bug...

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

PS: I consider it as a bug: Change the array specifier in this line to 1000:

    LogEntries              leLogEntries [1000] {};

g ++将产生5'000警告!

g++ will produce 5'000 warnings! I would suppose that it does not really make sense to repeat the warning for each array value.

推荐答案

更新:

UPDATE:

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

ICE [内部编译器错误]现在位于错误数据库 GNU错误资料库

这似乎是一个错误。我现在在玩一些,我得到一个修改编译器消息gcc因为一个内部错误停止。

It seems to be a bug. I was now playing a bit around and I get after a modification the compiler message gcc stopped because of an internal error.

UPDATE:代码不能由gcc编译。编译器选项: g ++ -std = c ++ 11 gcc-warning-bug.cpp -Wall -Wextra -Werror -fno-strict-aliasing -fwrapv -fno-aggressive-loop- optimizations -c - 有些选项存在,因为GNU请求它的错误报告。

UPDATE: As requested the code which cannot be compiled by gcc. Compiler options: g++ -std=c++11 gcc-warning-bug.cpp -Wall -Wextra -Werror -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -c - some options are there because GNU requests it for a bug report.

#include <atomic>

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

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

LogEntries LogThreads::leLogEntries [10] {};

编译器失败,输出结果如下:

Compiler fails with this output:

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 是静态的。

I will prepare the sample code and submit it to the developer team. In my project the member leLogEntries is static.

当你删除 std ::原子行然后它工作 - > std :: atomic 实现中的问题

When you remove the std::atomic line then it works --> problem in the std::atomic implementation?

这篇关于gcc 4.9.2 bug in -Wmissing-field-initializers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆