diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-12-14 19:38:25 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-12-14 19:38:25 +0000 |
commit | 52f14b2c8c8f499152413584724589eb9c86bb20 (patch) | |
tree | 6c2b4646df17cb5b7c481f47b94c44bffd17c4f0 /gcc/cp/cp-objcp-common.c | |
parent | a74c8d05f15407fb3bef9c3ca49401c4a8868763 (diff) | |
download | gcc-52f14b2c8c8f499152413584724589eb9c86bb20.tar.gz |
PR c++/18793
* cp-objcp-common.c (cp_expr_size): Loosen assertion.
PR c++/18793
* g++.dg/init/aggr3.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@92156 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/cp-objcp-common.c')
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index 9938b98f535..d43c159c01f 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -75,21 +75,36 @@ cxx_warn_unused_global_decl (tree decl) tree cp_expr_size (tree exp) { - if (CLASS_TYPE_P (TREE_TYPE (exp))) + tree type = TREE_TYPE (exp); + + if (CLASS_TYPE_P (type)) { /* The backend should not be interested in the size of an expression of a type with both of these set; all copies of such types must go through a constructor or assignment op. */ - gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp)) - || !TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)) + gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (type) + || !TYPE_HAS_COMPLEX_ASSIGN_REF (type) /* But storing a CONSTRUCTOR isn't a copy. */ - || TREE_CODE (exp) == CONSTRUCTOR); + || TREE_CODE (exp) == CONSTRUCTOR + /* And, the gimplifier will sometimes make a copy of + an aggregate. In particular, for a case like: + + struct S { S(); }; + struct X { int a; S s; }; + X x = { 0 }; + + the gimplifier will create a temporary with + static storage duration, perform static + initialization of the temporary, and then copy + the result. Since the "s" subobject is never + constructed, this is a valid transformation. */ + || CP_AGGREGATE_TYPE_P (type)); /* This would be wrong for a type with virtual bases, but they are caught by the assert above. */ - return (is_empty_class (TREE_TYPE (exp)) + return (is_empty_class (type) ? size_zero_node - : CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp))); + : CLASSTYPE_SIZE_UNIT (type)); } else /* Use the default code. */ |