This fixes a bogus -Wuninitialized warning: there's nothing to initialize
in empty classes, so don't add them into our uninitialized set.
PR c++/19808
gcc/cp/ChangeLog:
* init.c (emit_mem_initializers): Don't add is_really_empty_class
members into uninitialized.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wuninitialized-28.C: Make a class nonempty.
* g++.dg/warn/Wuninitialized-29.C: Likewise.
* g++.dg/warn/Wuninitialized-31.C: New test.
for (tree f = next_initializable_field (TYPE_FIELDS (current_class_type));
f != NULL_TREE;
f = next_initializable_field (DECL_CHAIN (f)))
- if (!DECL_ARTIFICIAL (f))
+ if (!DECL_ARTIFICIAL (f)
+ && !is_really_empty_class (TREE_TYPE (f), /*ignore_vptr*/false))
uninitialized.add (f);
if (mem_inits
};
struct bar {
+ int a;
bar() {}
bar(bar&) {}
};
};
struct bar {
+ int a;
bar() {}
bar(bar&) {}
};
--- /dev/null
+// PR c++/19808
+// { dg-do compile }
+// { dg-options "-Wuninitialized" }
+
+class AllocatorWithCleanup {
+public:
+ int *allocate(int);
+};
+class SecBlock {
+ SecBlock() : m_ptr(m_alloc.allocate(0)) {} // { dg-bogus "uninitialized" }
+ AllocatorWithCleanup m_alloc;
+ int *m_ptr;
+};
+
+struct A {
+ int *allocate(int);
+};
+
+struct B {
+ int : 0;
+ int *allocate(int);
+};
+
+struct C : B {
+};
+
+struct D {
+ char arr[0];
+ int *allocate(int);
+};
+
+struct E { };
+
+struct F {
+ E arr[10];
+ int *allocate(int);
+};
+
+struct G {
+ E e;
+ int *allocate(int);
+};
+
+struct H {
+ virtual void foo ();
+ int *allocate(int);
+};
+
+template<typename T>
+struct X {
+ X() : m_ptr(t.allocate(0)) {} // { dg-bogus "uninitialized" }
+ T t;
+ int *m_ptr;
+};
+
+struct V {
+ int a;
+ int *allocate(int);
+};
+
+struct Z {
+ Z() : m_ptr(v.allocate(0)) {} // { dg-warning "uninitialized" }
+ V v;
+ int *m_ptr;
+};
+
+X<A> x1;
+X<B> x2;
+X<C> x3;
+X<D> x4;
+X<F> x5;
+X<G> x6;
+X<H> x7;