From patchwork Fri Dec 18 17:45:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 559035 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 770141401DA for ; Sat, 19 Dec 2015 04:46:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ZVwYO048; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=g4h2HvPwmB7r 7wiPTnUk9Sdna8qHHIvP5CW6GZJhdYriqI8yAlwf6P15Be0PxUoWgAjyRRUGighx TQG0QXa3bU3ipP0kPZsvkhhJoK/w42dFw/sNdivHrb6Vq3bgHcV/Dn+Nnb1f796S ao1vLJKnyh8vTx0IznoanfsCOJ7d+TM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=x65xHGLnl+5RhKpfoK +0d4u8W6o=; b=ZVwYO048mVzDIDObeP6GeBIwPK5J8+DEHuL6302yX0cTcHzuhX g2O4HZzDa1jm9R7Z6j2yQDGqZ8Rv8/zsOFClvFAdGOkI4iCH1UVGFm2DY9kjSEGo W14bL/EAH0lync83SzQHvgjdRp/vlhrep2fAVLnELPCRh5gksV0l+CH+Y= Received: (qmail 122200 invoked by alias); 18 Dec 2015 17:46:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 122175 invoked by uid 89); 18 Dec 2015 17:46:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=LHS X-HELO: mail-qg0-f44.google.com Received: from mail-qg0-f44.google.com (HELO mail-qg0-f44.google.com) (209.85.192.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 18 Dec 2015 17:46:07 +0000 Received: by mail-qg0-f44.google.com with SMTP id v36so38491225qgd.2 for ; Fri, 18 Dec 2015 09:46:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4Gg/Je2vctSoBZG93G00ZYzJ4YbvEhD7b1JEVR4lROQ=; b=hhfBkUmFdCbdOPJS04QY5O3+iyUY1lMgbE4BWoYxGROAVFuvdA3fTwvW6I3Ltl89kR np8gpT0/RcsIn0/FH2ykz84zj8wgDDd9wGj7M+JLoS53pCeFvYQTGGpjR3/EM/F6NjoI aZCoPpjcgJvk1t99jzDifLMJGnrsnmB2bi03z1XWHgUL0edo+rmIxm+dAoV3L1uEi/Bn Pu6FnyKWHPGPNiEt9hfNbijLPXend5oCWeEbf/QcYj6rViRG1Unub565/bJSKDHnBHIk 6MJW6BGj2e7VcwF3jOr+d5JliacVdCVwDfxZGmQD1jyioXMRTkClFOB+vJyi19m3zReY /i7g== X-Gm-Message-State: ALoCoQmEAOVUivdDQFfc3yotkeVomovYoxz7l3l8wushA+jTWOB9Fv+vry2AAvD6LwElksUb8P4E1YJ8y3qDP+ZCIv1M/fTWMw== X-Received: by 10.140.25.145 with SMTP id 17mr6893444qgt.96.1450460765489; Fri, 18 Dec 2015 09:46:05 -0800 (PST) Received: from localhost.localdomain (ool-4353a8be.dyn.optonline.net. [67.83.168.190]) by smtp.gmail.com with ESMTPSA id p191sm362159qha.25.2015.12.18.09.46.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Dec 2015 09:46:05 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix PR c++/68978 (bogus error: lvalue required as left operand of assignment) Date: Fri, 18 Dec 2015 12:45:19 -0500 Message-Id: <1450460719-4913-1-git-send-email-patrick@parcs.ath.cx> Before my patch for PR c++/21802, the function build_x_modify_expr() did not call build_new_op() during template processing (and thus did not do operator lookup); instead, it just built and returned a raw MODOP_EXPR. After my patch, the function build_x_modify_expr() now calls build_new_op() even when processing a template. And when building a MODOP_EXPR/MODIFY_EXPR, build_new_op() eventually calls cp_build_modify_expr(), but that function apparently is not prepared to handle a MODIFY_EXPR whose LHS is a MODOP_EXPR, ultimately because it calls lvalue_kind() (via lvalue_or_else()) which returns clk_none for a MODOP_EXPR. And a non-lvalue can't be the LHS to a MODIFY_EXPR. Again, we did not have this problem before the mentioned patch because build_x_modify_expr() originally did not call build_new_op() at all during template processing. This is now necessary to in order to do operator lookup at template definition time. To fix this, I think lvalue_kind() should handle a MODOP_EXPR the same as a MODIFY_EXPR, at least during template processing, so it should return clk_ordinary instead of clk_none. Though I'm not sure if the added assert is entirely correct or appropriate.. Bootstrap and regtest in progress on x86_64-pc-linux-gnu, OK to commit if testing is OK? I will also try to build and test boost with this change. gcc/cp/ChangeLog: PR c++/68978 * tree.c (lvalue_kind) [MODOP_EXPR]: New case. gcc/testsuite/ChangeLog: PR c++/68978 * g++.dg/template/pr68978.C: New test. --- gcc/cp/tree.c | 6 +++++ gcc/testsuite/g++.dg/template/pr68978.C | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/pr68978.C diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index ae176d0..250fe27 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -185,6 +185,12 @@ lvalue_kind (const_tree ref) op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2)); break; + case MODOP_EXPR: + /* We expect to see unlowered MODOP_EXPRs only during + template processing. */ + gcc_assert (processing_template_decl); + return clk_ordinary; + case MODIFY_EXPR: case TYPEID_EXPR: return clk_ordinary; diff --git a/gcc/testsuite/g++.dg/template/pr68978.C b/gcc/testsuite/g++.dg/template/pr68978.C new file mode 100644 index 0000000..b5946fc --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr68978.C @@ -0,0 +1,44 @@ +// PR c++/68978 + +extern int x, y, z; + +template int toi_1() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i *= radix) += c)) + return 0; + return i; +} + +template int toi_2() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i = radix) = c)) + return 0; + return i; +} + +template int toi_3() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i = radix) += c)) + return 0; + return i; +} + +template int toi_4() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < ((i += radix) = c)) + return 0; + return i; +} + +template int toi_5() { + int i = 0, c = 0, radix = 10, max = 0x7fffffff; + if (max < (((i = radix) = (c += 5)) *= 30)) + return 0; + return i; +} + +int a = toi_1 (); +int b = toi_2 (); +int c = toi_3 (); +int d = toi_4 (); +int e = toi_5 ();