c++ - Warnings for uninitialized members disappear on the C++11 -


i compile simple program:

#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 %d\n", foo.a, foo.b);      return 0; } 

and warnings:

$ 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’ used uninitialized in function [-wuninitialized]      printf("%d %d\n", foo.a, foo.b);            ^ foo.cpp:23:11: warning: ‘foo.foo::a’ used uninitialized in function [-wuninitialized] 

of course, expect. when uncomment bar default ctor, there problem - warnings disappear.

why bar ctor disables warnings foo?

my gcc version is: g++ (ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609.

the problem not occur on c++03, on c++11 or newer.

it's compiler bug, jarod pointed out, has been fixed.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -