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
This commit is contained in:
parent
84d594c648
commit
88f7a9f691
|
@ -1,5 +1,9 @@
|
||||||
2012-02-07 Jason Merrill <jason@redhat.com>
|
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
|
PR c++/52035
|
||||||
* pt.c (tsubst): Strip uninstantiated typedef.
|
* pt.c (tsubst): Strip uninstantiated typedef.
|
||||||
|
|
||||||
|
|
|
@ -6025,13 +6025,28 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain)
|
||||||
bool bad;
|
bool bad;
|
||||||
tree field;
|
tree field;
|
||||||
unsigned i, nelts;
|
unsigned i, nelts;
|
||||||
|
tree ctype;
|
||||||
|
|
||||||
if (TREE_CODE (body) != CONSTRUCTOR)
|
if (TREE_CODE (body) != CONSTRUCTOR)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bad = false;
|
|
||||||
nelts = CONSTRUCTOR_NELTS (body);
|
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)
|
for (i = 0; i <= nelts; ++i)
|
||||||
{
|
{
|
||||||
tree index;
|
tree index;
|
||||||
|
@ -6050,8 +6065,6 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain)
|
||||||
if (TREE_CODE (field) != FIELD_DECL
|
if (TREE_CODE (field) != FIELD_DECL
|
||||||
|| (DECL_C_BIT_FIELD (field) && !DECL_NAME (field)))
|
|| (DECL_C_BIT_FIELD (field) && !DECL_NAME (field)))
|
||||||
continue;
|
continue;
|
||||||
if (!complain)
|
|
||||||
return true;
|
|
||||||
ftype = strip_array_types (TREE_TYPE (field));
|
ftype = strip_array_types (TREE_TYPE (field));
|
||||||
if (type_has_constexpr_default_constructor (ftype))
|
if (type_has_constexpr_default_constructor (ftype))
|
||||||
{
|
{
|
||||||
|
@ -6062,6 +6075,8 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain)
|
||||||
|| errorcount != 0);
|
|| errorcount != 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!complain)
|
||||||
|
return true;
|
||||||
error ("uninitialized member %qD in %<constexpr%> constructor",
|
error ("uninitialized member %qD in %<constexpr%> constructor",
|
||||||
field);
|
field);
|
||||||
bad = true;
|
bad = true;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
2012-02-07 Jason Merrill <jason@redhat.com>
|
2012-02-07 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
PR c++/51675
|
||||||
|
* g++.dg/cpp0x/constexpr-union3.C: New.
|
||||||
|
|
||||||
PR c++/52035
|
PR c++/52035
|
||||||
* g++.dg/lto/pr52035_0.C: New.
|
* g++.dg/lto/pr52035_0.C: New.
|
||||||
|
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue