aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2009-03-05 09:10:07 -0500
committerJason Merrill <jason@gcc.gnu.org>2009-03-05 09:10:07 -0500
commit2588c9e970ebea8cd91d3ba9b38ccd909e063c30 (patch)
tree471c77be303fe10eedd997165d69dae2bf932fad
parentee0ee7e2c1fd52af141b14c0230dcf6cd50c2b35 (diff)
downloadgcc-2588c9e970ebea8cd91d3ba9b38ccd909e063c30.zip
gcc-2588c9e970ebea8cd91d3ba9b38ccd909e063c30.tar.gz
gcc-2588c9e970ebea8cd91d3ba9b38ccd909e063c30.tar.bz2
re PR c++/38908 (Unexplained "'<anonymous>' is used uninitialized in this function" warning in cc1plus -m64)
PR c++/38908 * class.c (is_really_empty_class): New fn. * cp-tree.h: Declare it. * cp-objcp-common.c (cp_expr_size): Use it. From-SVN: r144643
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/class.c33
-rw-r--r--gcc/cp/cp-objcp-common.c2
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/warn/Wuninitialized-3.C17
6 files changed, 61 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 187ade4..31a626b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2009-03-04 Jason Merrill <jason@redhat.com>
+ PR c++/38908
+ * class.c (is_really_empty_class): New fn.
+ * cp-tree.h: Declare it.
+ * cp-objcp-common.c (cp_expr_size): Use it.
+
PR c++/13549
* semantics.c (perform_koenig_lookup): Handle TEMPLATE_ID_EXPR.
* parser.c (cp_parser_postfix_expression): Call it for
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index ae89218..b8553ef 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -6461,7 +6461,7 @@ is_empty_class (tree type)
if (type == error_mark_node)
return 0;
- if (! MAYBE_CLASS_TYPE_P (type))
+ if (! CLASS_TYPE_P (type))
return 0;
/* In G++ 3.2, whether or not a class was empty was determined by
@@ -6501,6 +6501,37 @@ contains_empty_class_p (tree type)
return false;
}
+/* Returns true if TYPE contains no actual data, just various
+ possible combinations of empty classes. */
+
+bool
+is_really_empty_class (tree type)
+{
+ if (is_empty_class (type))
+ return true;
+ if (CLASS_TYPE_P (type))
+ {
+ tree field;
+ tree binfo;
+ tree base_binfo;
+ int i;
+
+ for (binfo = TYPE_BINFO (type), i = 0;
+ BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
+ if (!is_really_empty_class (BINFO_TYPE (base_binfo)))
+ return false;
+ for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
+ if (TREE_CODE (field) == FIELD_DECL
+ && !DECL_ARTIFICIAL (field)
+ && !is_really_empty_class (TREE_TYPE (field)))
+ return false;
+ return true;
+ }
+ else if (TREE_CODE (type) == ARRAY_TYPE)
+ return is_really_empty_class (TREE_TYPE (type));
+ return false;
+}
+
/* Note that NAME was looked up while the current class was being
defined and that the result of that lookup was DECL. */
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c
index 7d2e870..fefafb1 100644
--- a/gcc/cp/cp-objcp-common.c
+++ b/gcc/cp/cp-objcp-common.c
@@ -101,7 +101,7 @@ cp_expr_size (const_tree exp)
constructed, this is a valid transformation. */
|| CP_AGGREGATE_TYPE_P (type))
/* This would be wrong for a type with virtual bases. */
- return (is_empty_class (type)
+ return (is_really_empty_class (type)
? size_zero_node
: CLASSTYPE_SIZE_UNIT (type));
else
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b6bf7d4..aedf5b9 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4240,6 +4240,7 @@ extern void finish_struct_1 (tree);
extern int resolves_to_fixed_type_p (tree, int *);
extern void init_class_processing (void);
extern int is_empty_class (tree);
+extern bool is_really_empty_class (tree);
extern void pushclass (tree);
extern void popclass (void);
extern void push_nested_class (tree);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f71de1c..37c4074 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-05 Jason Merrill <jason@redhat.com>
+
+ PR c++/38908
+ * g++.dg/warn/Wuninitialized-3.C: New test.
+
2009-03-05 Jakub Jelinek <jakub@redhat.com>
PR debug/39379
diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-3.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-3.C
new file mode 100644
index 0000000..dc3be3f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-3.C
@@ -0,0 +1,17 @@
+// PR C++/38908
+// { dg-options "-Wuninitialized -O" }
+
+struct empty {};
+
+struct dfs_visitor {
+ dfs_visitor() { }
+ empty m_vis;
+};
+
+void bar(const dfs_visitor&);
+void foo(void)
+{
+ dfs_visitor vis;
+ dfs_visitor vis2 = vis;
+ bar (vis2);
+}