From 321774e81d15fc62f831ce42b80b7762a328aee5 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Sun, 1 May 2005 23:26:25 +0000 Subject: [PATCH] re PR c++/18464 (error message about "non-lvalue in unary '&'" when using ?: operator) PR c++/18464 * call.c (build_this): In templates, do not bother with build_unary_op. * typeck.c (unary_complex_lvalue): In a template, always refuse simplifications. PR c++/18464 * g++.dg/template/cond5.C: New test. From-SVN: r99084 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/call.c | 10 +++++++++- gcc/cp/typeck.c | 9 ++++++++- gcc/testsuite/ChangeLog | 5 +++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2622d073203b..51dc307d5e4f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2004-12-22 Mark Mitchell + + PR c++/18464 + * call.c (build_this): In templates, do not bother with + build_unary_op. + * typeck.c (unary_complex_lvalue): In a template, always refuse + simplifications. + 2005-04-25 Roger Sayle Mark Mitchell diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 14b877cc415f..aeed3155df4b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2203,10 +2203,18 @@ any_strictly_viable (struct z_candidate *cands) return false; } +/* OBJ is being used in an expression like "OBJ.f (...)". In other + words, it is about to become the "this" pointer for a member + function call. Take the address of the object. */ + static tree build_this (tree obj) { - /* Fix this to work on non-lvalues. */ + /* In a template, we are only concerned about the type of the + expression, so we can take a shortcut. */ + if (processing_template_decl) + return build_address (obj); + return build_unary_op (ADDR_EXPR, obj, 0); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 634ca6685fbf..3af17a8b95f0 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4166,11 +4166,18 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert) for certain kinds of expressions which are not really lvalues but which we can accept as lvalues. - If ARG is not a kind of expression we can handle, return zero. */ + If ARG is not a kind of expression we can handle, return + NULL_TREE. */ tree unary_complex_lvalue (enum tree_code code, tree arg) { + /* Inside a template, making these kinds of adjustments is + pointless; we are only concerned with the type of the + expression. */ + if (processing_template_decl) + return NULL_TREE; + /* Handle (a, b) used as an "lvalue". */ if (TREE_CODE (arg) == COMPOUND_EXPR) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 67bc542aa978..f179a5cc7de5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-12-22 Mark Mitchell + + PR c++/18464 + * g++.dg/template/cond5.C: New test. + 2005-05-01 Joseph S. Myers PR c/21213 -- 2.47.2