summaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2010-07-14 17:00:51 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2010-07-14 17:00:51 +0000
commit80e5473297f3b9131a8e689f9a60714e486c72fb (patch)
tree152c38c98a68f7f49ca34046d6b08f92764dea84 /gcc/cp/class.c
parent83ae9b01ce9a1bf67beba922bd48b1b3e91c673e (diff)
downloadgcc-80e5473297f3b9131a8e689f9a60714e486c72fb.tar.gz
Implement C++0x unrestricted unions (N2544)
* class.c (check_field_decl): Loosen union handling in C++0x. * method.c (walk_field_subobs): Split out from... (synthesized_method_walk): ...here. Set msg before loops. (process_subob_fn): Check for triviality in union members. * init.c (sort_mem_initializers): Splice out uninitialized anonymous unions and union members. (push_base_cleanups): Don't automatically destroy anonymous unions and union members. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162187 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index ed7367c95c4..a572af83f63 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2864,9 +2864,9 @@ check_field_decl (tree field,
{
tree type = strip_array_types (TREE_TYPE (field));
- /* An anonymous union cannot contain any fields which would change
+ /* In C++98 an anonymous union cannot contain any fields which would change
the settings of CANT_HAVE_CONST_CTOR and friends. */
- if (ANON_UNION_TYPE_P (type))
+ if (ANON_UNION_TYPE_P (type) && cxx_dialect < cxx0x)
;
/* And, we don't set TYPE_HAS_CONST_COPY_CTOR, etc., for anonymous
structs. So, we recurse through their fields here. */
@@ -2888,8 +2888,10 @@ check_field_decl (tree field,
make it through without complaint. */
abstract_virtuals_error (field, type);
- if (TREE_CODE (t) == UNION_TYPE)
+ if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx0x)
{
+ static bool warned;
+ int oldcount = errorcount;
if (TYPE_NEEDS_CONSTRUCTING (type))
error ("member %q+#D with constructor not allowed in union",
field);
@@ -2898,8 +2900,12 @@ check_field_decl (tree field,
if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
error ("member %q+#D with copy assignment operator not allowed in union",
field);
- /* Don't bother diagnosing move assop now; C++0x has more
- flexible unions. */
+ if (!warned && errorcount > oldcount)
+ {
+ inform (DECL_SOURCE_LOCATION (field), "unrestricted unions "
+ "only available with -std=c++0x or -std=gnu++0x");
+ warned = true;
+ }
}
else
{