diff options
author | Jason Merrill <jason@redhat.com> | 2012-02-08 04:52:19 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2012-02-08 04:52:19 -0500 |
commit | 88f7a9f691c91abf96a2ebe01e8e9dacb57d2426 (patch) | |
tree | 1effa9fa3ac6b2ec9153c656ca5818fd538b0542 /gcc | |
parent | 84d594c6487e4502beb72786cdd82c234b549a98 (diff) | |
download | gcc-88f7a9f691c91abf96a2ebe01e8e9dacb57d2426.zip gcc-88f7a9f691c91abf96a2ebe01e8e9dacb57d2426.tar.gz gcc-88f7a9f691c91abf96a2ebe01e8e9dacb57d2426.tar.bz2 |
re PR c++/51675 ([C++11][4.7 Regression] Cannot create constexpr unions)
PR c++/51675
* semantics.c (cx_check_missing_mem_inits): Handle unions.
Fix constexpr default constructor logic.
From-SVN: r184001
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 23 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-union3.C | 12 |
4 files changed, 38 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b506f4b..f9246e5 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 9019962..5646fa7 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9f50b24..482b489 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2012-02-07 Jason Merrill <jason@redhat.com> + PR c++/51675 + * g++.dg/cpp0x/constexpr-union3.C: New. + PR c++/52035 * g++.dg/lto/pr52035_0.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-union3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-union3.C new file mode 100644 index 0000000..bac9cab --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-union3.C @@ -0,0 +1,12 @@ +// PR c++/51675 +// { dg-options -std=c++11 } + +union foo +{ + int x; + short y; + + constexpr foo(): x(0) { } +}; + +constexpr foo f; |