diff options
author | Mark Mitchell <mark@codesourcery.com> | 2005-04-06 05:38:34 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2005-04-06 05:38:34 +0000 |
commit | 6d05585b7582f089450927448e7659f62d2bdfab (patch) | |
tree | 8ed15eb7577a955c2551d3817fd8ac67763a4022 /gcc/cp | |
parent | 05b205e83002ac5988c22383846fe318b8c1a4fc (diff) | |
download | gcc-6d05585b7582f089450927448e7659f62d2bdfab.zip gcc-6d05585b7582f089450927448e7659f62d2bdfab.tar.gz gcc-6d05585b7582f089450927448e7659f62d2bdfab.tar.bz2 |
re PR c++/20734 (rejects valid pointer to member)
PR c++/20734
* cp-tree.def (OFFSET_REF): Correct comments.
* init.c (build_offset_ref): Remove misleading comment.
* typeck.c (build_unary_op): Handle pointer-to-member creation
here, rather than ...
(unary_complex_lvalue): ... here.
PR c++/20734
* g++.dg/template/ptrmem13.C: New test.
From-SVN: r97696
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-tree.def | 6 | ||||
-rw-r--r-- | gcc/cp/init.c | 3 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 70 |
3 files changed, 26 insertions, 53 deletions
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index 1abc77b..00f2aa1 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -31,10 +31,8 @@ Boston, MA 02111-1307, USA. */ BASELINK, or TEMPLATE_ID_EXPR (corresponding to `m'). The expression is a pointer-to-member if its address is taken, - but simply denotes a member of the object if its address isnot - taken. In the latter case, resolve_offset_ref is used to - convert it to a representation of the member referred to by the - OFFSET_REF. + but simply denotes a member of the object if its address is not + taken. This form is only used during the parsing phase; once semantic analysis has taken place they are eliminated. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 69089fe..726309a 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1551,9 +1551,6 @@ build_offset_ref (tree type, tree name, bool address_p) return member; } - /* In member functions, the form `type::name' is no longer - equivalent to `this->type::name', at least not until - resolve_offset_ref. */ member = build2 (OFFSET_REF, TREE_TYPE (member), decl, member); PTRMEM_OK_P (member) = 1; return member; diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index a3bf1c0..272dc86 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4026,6 +4026,29 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert) arg = OVL_CURRENT (arg); break; + case OFFSET_REF: + /* Turn a reference to a non-static data member into a + pointer-to-member. */ + { + tree type; + tree t; + + if (!PTRMEM_OK_P (arg)) + return build_unary_op (code, arg, 0); + + t = TREE_OPERAND (arg, 1); + if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) + { + error ("cannot create pointer to reference member %qD", t); + return error_mark_node; + } + + type = build_ptrmem_type (context_for_name_lookup (t), + TREE_TYPE (t)); + t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1)); + return t; + } + default: break; } @@ -4182,52 +4205,7 @@ unary_complex_lvalue (enum tree_code code, tree arg) if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE || TREE_CODE (arg) == OFFSET_REF) - { - tree t; - - gcc_assert (TREE_CODE (arg) != SCOPE_REF); - - if (TREE_CODE (arg) != OFFSET_REF) - return 0; - - t = TREE_OPERAND (arg, 1); - - /* Check all this code for right semantics. */ - if (TREE_CODE (t) == FUNCTION_DECL) - { - if (DECL_DESTRUCTOR_P (t)) - error ("taking address of destructor"); - return build_unary_op (ADDR_EXPR, t, 0); - } - if (TREE_CODE (t) == VAR_DECL) - return build_unary_op (ADDR_EXPR, t, 0); - else - { - tree type; - - if (TREE_OPERAND (arg, 0) - && ! is_dummy_object (TREE_OPERAND (arg, 0)) - && TREE_CODE (t) != FIELD_DECL) - { - error ("taking address of bound pointer-to-member expression"); - return error_mark_node; - } - if (!PTRMEM_OK_P (arg)) - return build_unary_op (code, arg, 0); - - if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) - { - error ("cannot create pointer to reference member %qD", t); - return error_mark_node; - } - - type = build_ptrmem_type (context_for_name_lookup (t), - TREE_TYPE (t)); - t = make_ptrmem_cst (type, TREE_OPERAND (arg, 1)); - return t; - } - } - + return NULL_TREE; /* We permit compiler to make function calls returning objects of aggregate type look like lvalues. */ |