- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这段代码中遇到问题 - 可以将其 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/
我正在尝试做这样的事情..我有 3 个头文件 1. coordinates.h typedef struct { float x; float y; float z; }coordinat
我知道顾名思义,它会在缺少字段初始值设定项时触发。但它没有触发以下代码的任何警告。 #include struct test { int a, b, c; }; void func(stru
我正在使用 GCC 4.6.2 (Mingw) 并使用 -Wextra 进行编译。每当我使用指定的初始值设定项时,我都会收到奇怪的警告。对于以下代码 typedef struct { int x;
当存在隐式导入时,GHC 会生成警告(见下文)。目标是用显式导入替换这些。是否有自动生成列表的方法(而不是在代码中手动查找)? /Users/srid/code/slownews/backend/sr
考虑以下程序: #include int main() { std::array x = { 0 }; // warning! x = { { 0 } }; // no warning
考虑以下程序: #include int main() { std::array x = { 0 }; // warning! x = { { 0 } }; // no warning
我在这段代码中遇到问题 - 可以将其 1:1 复制到 cpp 文件中以测试行为: #include typedef struct { char sDateTim
我正在尝试使用宏以默认值初始化结构元素。不幸的是,我不断收到警告,但我无法找到其解决方案,任何人都可以帮助我了解我到底做错了什么吗? 注意: 我在初始化时收到警告。 我已经尝试了这两个宏,但仍然无法解
我使用启用了 -Wall 和 -Wextra 的 GCC 编译了一些代码。此代码会产生警告: struct A { A(int) {} }; struct B {}; struct C : A, B
我想知道为什么我在一种情况下收到关于初始化的警告,而在另一种情况下却没有。该代码位于C++源文件中,并将GCC 4.7与-std=c++11结合使用。 struct sigaction old_han
我遇到了以下结构: static struct { unsigned char a[5]; } b[] = { {1,1,1,1,1}, {2,2,
我正在使用 MPLABX(Microchip 产品的 IDE)和 XC16 编译器(基于 GCC)用 C 编写嵌入式代码。 我正在使用 -Wmissing-prototypes 来确保我拥有所有函数的
我有这个代码: #include int main(int, char **argv) { std::array a = {1,2,3}; } 这编译得很好 (-std=c++11) ,但如果
代码 GValue value = { 0 }; 给出以下警告: missing initializer [-Wmissing-field-initializers] 我知道那是 GCC bug
我是一名优秀的程序员,十分优秀!