gcc 4.9.2 bug in -Wmissing-field-initializers?

大憨熊 提交于 2019-12-11 10:43:49

问题


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;

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]

Adding the {} initializer in this line

std::atomic<bool>   bReadyToFlush {};

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

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.

EDIT: 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: I consider it as a bug: Change the array specifier in this line to 1000:

    LogEntries              leLogEntries [1000] {};

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


回答1:


UPDATE:

The 1st case is now confirmed by GNU it is a bug but already fixed in gcc 5.0

The ICE [Internal Compiler Error] is now in the bug database GNU bug database

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: 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.

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

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



来源:https://stackoverflow.com/questions/29184431/gcc-4-9-2-bug-in-wmissing-field-initializers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!