diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-08 09:52:19 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-08 09:52:19 +0000 |
commit | 2e5f66c6c3997b728c30c7de11c894cd7a381b10 (patch) | |
tree | 1effa9fa3ac6b2ec9153c656ca5818fd538b0542 /gcc/cp | |
parent | 44f861fca343148a1b0720105ec2b7f14bbcc849 (diff) | |
download | gcc-2e5f66c6c3997b728c30c7de11c894cd7a381b10.tar.gz |
PR c++/51675
* semantics.c (cx_check_missing_mem_inits): Handle unions.
Fix constexpr default constructor logic.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184001 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 23 |
2 files changed, 23 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b506f4bd055..f9246e56b74 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2012-02-07 Jason Merrill <jason@redhat.com> + PR c++/51675 + * semantics.c (cx_check_missing_mem_inits): Handle unions. + Fix constexpr default constructor logic. + PR c++/52035 * pt.c (tsubst): Strip uninstantiated typedef. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 90199624876..5646fa74717 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6025,13 +6025,28 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain) bool bad; tree field; unsigned i, nelts; + tree ctype; if (TREE_CODE (body) != CONSTRUCTOR) return false; - bad = false; nelts = CONSTRUCTOR_NELTS (body); - field = TYPE_FIELDS (DECL_CONTEXT (fun)); + ctype = DECL_CONTEXT (fun); + field = TYPE_FIELDS (ctype); + + if (TREE_CODE (ctype) == UNION_TYPE) + { + if (nelts == 0 && next_initializable_field (field)) + { + if (complain) + error ("%<constexpr%> constructor for union %qT must " + "initialize exactly one non-static data member", ctype); + return true; + } + return false; + } + + bad = false; for (i = 0; i <= nelts; ++i) { tree index; @@ -6050,8 +6065,6 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain) if (TREE_CODE (field) != FIELD_DECL || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))) continue; - if (!complain) - return true; ftype = strip_array_types (TREE_TYPE (field)); if (type_has_constexpr_default_constructor (ftype)) { @@ -6062,6 +6075,8 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain) || errorcount != 0); continue; } + if (!complain) + return true; error ("uninitialized member %qD in %<constexpr%> constructor", field); bad = true; |