对于未初始化成员的警告在c++ 11中消失
Warnings for uninitialized members disappear on the C++11
我编译了这个简单的程序:
#include <cstdio>
#include <iostream>
using namespace std;
struct Foo
{
int a;
int b;
};
struct Bar
{
//Bar() = default;
int d;
};
int main()
{
Foo foo;
Bar bar;
printf("%d %dn", foo.a, foo.b);
return 0;
}
我得到了这些警告:
$ g++ -std=c++11 -Wall -Wextra -Wpedantic foo.cpp -o foo
foo.cpp: In function ‘int main()’:
foo.cpp:21:9: warning: unused variable ‘bar’ [-Wunused-variable]
Bar bar;
^
foo.cpp:23:11: warning: ‘foo.Foo::b’ is used uninitialized in this function [-Wuninitialized]
printf("%d %dn", foo.a, foo.b);
^
foo.cpp:23:11: warning: ‘foo.Foo::a’ is used uninitialized in this function [-Wuninitialized]
当然,这是我们所期望的。但是,当我取消注释Bar
默认变量时,有一个问题-所有警告都消失了。
为什么Bar
会禁用Foo
的警告?
我的GCC版本是:g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
.
这个问题不会在c++ 03上出现,只会在c++ 11或更新的版本上出现
这是一个编译器错误,正如Jarod指出的,已经修复了。
相关文章:
- 将地址分配给本地指针后,公共对象的变量将消失
- 应用投影矩阵后对象消失
- 添加自定义析构函数时,Move 构造函数在派生类中消失
- 在 Linux 中使用 ioctl() 获取隐藏功能报告时,零字节消失
- 应用地址清理器后,免费无效指针消失
- 返回的指针属性中类实例上的矢量属性消失
- 自动消失的自定义消息框
- 该程序没有产生输出,而是卡在一个循环中,几秒钟后消失并打印被杀死?
- C++ 在地图上循环 - 消失的对象
- 我收到一个断言错误,但是当我编写 cout 语句时,它会消失
- 使用Valgrind时内存泄漏消失
- 为什么在我释放左键单击后,我的绘图会消失
- 智能感知 PCH 警告不会消失
- C++ :: 设置值函数在函数内设置,但后跟 Get 函数,设置值消失了
- c++ – 消失的变量
- FreeGLUT窗口在启动时消失
- mysql c ++连接器异常:用户"root"@'localhost'的访问被拒绝(使用密码:NO)&&MySQL服务器已消失
- 我们如何在范围消失时通过引用返回变量
- MSVC C6029 警告:缓冲区可能溢出,使用未经检查的值.检查缓冲区大小时,警告不会消失
- 添加新纹理OpenGL时,模型消失了