From patchwork Tue Feb 23 15:58:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 586934 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 7E83D140BAC for ; Wed, 24 Feb 2016 02:58:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=v6FjqlA2; 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 :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=wRFR4j38bkeyMyzN Vr8Awn8jTlubhAW0/0eGO9z3/FHn9U/+daYwiVlbxHIhMqgQOQ9geCFa3eBSHT9B 3YBaFBLgP3IbXK44qUbxNC76cT92cY91VxfpmeC/Bg73q5Nvi5Cm8/lHdqxmNIOq RmzD/ltSxNHgR/MpjAZWYkKv0oM= 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 :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=xyuU6aRh5qOL7gwz0AolAj Jh+vc=; b=v6FjqlA2FL+qpc/+fOamW5oekWgUl/qnnyZ3DXmG3VFd1WI8625aVn OGMwKl9x+MkX/u769KY1WakiGEF4CgbCNikc21vWvFFh/5fcpInKXht/x/eKPnEZ p88yWP5/6IcG+8fuuTNKhQwIyJLayMSAsiWC72c7u/l8Vvy0Mxh3M= Received: (qmail 51136 invoked by alias); 23 Feb 2016 15:58:30 -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 51060 invoked by uid 89); 23 Feb 2016 15:58:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=call_expr, CALL_EXPR, mysteriously X-HELO: mail-qk0-f171.google.com Received: from mail-qk0-f171.google.com (HELO mail-qk0-f171.google.com) (209.85.220.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 23 Feb 2016 15:58:28 +0000 Received: by mail-qk0-f171.google.com with SMTP id s5so69582562qkd.0 for ; Tue, 23 Feb 2016 07:58:28 -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:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=EQ9ckqB95KYUkA6OUQxAiYJa+zZ82I4mTGy4Ju7s6a4=; b=jIgIfSRTa59huYZopoU6waz2xtphX26h1QFh/7ODqrmvR4cvv6uFxpVWgofczcFemc zxoz93NoMN76yxFCZ1u44z/qfk0zEtLcUmbb5BXns9qzVu9Va6fOBhjRVYH+g/dMyyQ0 NffZT2p7N2fRHON9fi3Csj+5sMF8/mes6PR7kH8dgmeLI+tgoUkwN2sHvtfJ4kLpQNgP NOkowYCjh7578kP/j53Xo5mUMVlvefBwroBMucAMrBacUxneOx/iM8zF5xDZA3ko5VgG ZXV3nxOsvLFOVYf7icnKzIdH7KgYDdP2v4+to0ywYFeEefdRND5p5aqUTZn3tOJSKzVi 0JnQ== X-Gm-Message-State: AG10YORg7GBBP9Qx1Fv4WTnahyS4Umf30l93drhL7kpEQDLugwfsqt3Ws/1kshcA26+9Zg== X-Received: by 10.55.71.135 with SMTP id u129mr43233094qka.26.1456243106146; Tue, 23 Feb 2016 07:58:26 -0800 (PST) Received: from [192.168.1.130] (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id y206sm8803971qhc.0.2016.02.23.07.58.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Feb 2016 07:58:25 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Tue, 23 Feb 2016 10:58:24 -0500 (EST) To: Marek Polacek cc: Patrick Palka , gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] Fix PR c++/69736 In-Reply-To: <20160223153144.GJ14947@redhat.com> Message-ID: References: <1456239521-25908-1-git-send-email-patrick@parcs.ath.cx> <20160223153144.GJ14947@redhat.com> User-Agent: Alpine 2.20.9 (DEB 106 2015-09-22) MIME-Version: 1.0 On Tue, 23 Feb 2016, Marek Polacek wrote: > On Tue, Feb 23, 2016 at 09:58:41AM -0500, Patrick Palka wrote: >> finish_call_expr thinks that a call to a function which has been >> obfuscated by force_paren_expr is a call to an unknown function. This >> eventually leads us to not make use of the function's default arguments >> when processing the argument list. So a function call like f() may >> compile and yet (f)() may not, if f has defaulted arguments. >> >> This patch fixes this inconsistency by making finish_call_expr undo the >> obfuscation performed by force_paren_expr. > > Thanks for the fix. > >> new file mode 100644 >> index 0000000..12462be >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/cpp1y/paren2.C >> @@ -0,0 +1,25 @@ >> +// PR c++/69736 >> + > > I'd expect > // { dg-do compile { target c++14 } } > here. Okay. > >> +void fn1(bool = true) >> +{ >> + (fn1)(); >> +} >> + >> +template >> +void fn2() >> +{ >> + (fn1)(); >> +} > > The test seems to fail here though because of > testsuite/g++.dg/cpp1y/paren2.C:11:9: error: too few arguments to function > Why's that? Oops... The call to maybe_undo_parenthesized_ref managed to mysteriously move itself to the wrong place. It should be called before the processing_template_decl logic, before FN gets wrapped in a NON_DEPENDENT_EXPR. Here's the updated patch, which I'm going to retest just in case. -- >8 -- gcc/cp/ChangeLog: PR c++/69736 * cp-tree.h (REF_PARENTHESIZED_P): Adjust documentation. (maybe_undo_parenthesized_ref): Declare. * semantics.c (maybe_undo_parenthesized_ref): Split out from check_return_expr. (finish_call_expr): Use it. * typeck.c (check_return_expr): Use it. gcc/testsuite/ChangeLog: PR c++/69736 * g++.dg/cpp1y/paren2.C: New test. --- gcc/cp/cp-tree.h | 3 ++- gcc/cp/semantics.c | 28 ++++++++++++++++++++++++++++ gcc/cp/typeck.c | 12 +----------- gcc/testsuite/g++.dg/cpp1y/paren2.C | 26 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/paren2.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 3c23a83a..88c6367 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3393,7 +3393,7 @@ extern void decl_shadowed_for_var_insert (tree, tree); TREE_LANG_FLAG_0 (STRING_CST_CHECK (NODE)) /* Indicates whether a COMPONENT_REF has been parenthesized, or an - INDIRECT_REF comes from parenthesizing a VAR_DECL. Currently only set + INDIRECT_REF comes from parenthesizing a _DECL. Currently only set some of the time in C++14 mode. */ #define REF_PARENTHESIZED_P(NODE) \ @@ -6361,6 +6361,7 @@ extern tree finish_label_stmt (tree); extern void finish_label_decl (tree); extern cp_expr finish_parenthesized_expr (cp_expr); extern tree force_paren_expr (tree); +extern tree maybe_undo_parenthesized_ref (tree); extern tree finish_non_static_data_member (tree, tree, tree); extern tree begin_stmt_expr (void); extern tree finish_stmt_expr_expr (tree, tree); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 38c7516..e5ecf48 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1673,6 +1673,30 @@ force_paren_expr (tree expr) return expr; } +/* If T is an id-expression obfuscated by force_paren_expr, undo the + obfuscation and return the underlying id-expression. Otherwise + return T. */ + +tree +maybe_undo_parenthesized_ref (tree t) +{ + if (cxx_dialect >= cxx14 + && INDIRECT_REF_P (t) + && REF_PARENTHESIZED_P (t)) + { + t = TREE_OPERAND (t, 0); + while (TREE_CODE (t) == NON_LVALUE_EXPR + || TREE_CODE (t) == NOP_EXPR) + t = TREE_OPERAND (t, 0); + + gcc_assert (TREE_CODE (t) == ADDR_EXPR + || TREE_CODE (t) == STATIC_CAST_EXPR); + t = TREE_OPERAND (t, 0); + } + + return t; +} + /* Finish a parenthesized expression EXPR. */ cp_expr @@ -2265,6 +2289,10 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, orig_fn = fn; + /* If FN is a FUNCTION_DECL obfuscated by force_paren_expr, undo + it so that we can tell this is a call to a known function. */ + fn = maybe_undo_parenthesized_ref (fn); + if (processing_template_decl) { /* If the call expression is dependent, build a CALL_EXPR node diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index d7ce327..3da6ea1 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8929,17 +8929,7 @@ check_return_expr (tree retval, bool *no_warning) /* If we had an id-expression obfuscated by force_paren_expr, we need to undo it so we can try to treat it as an rvalue below. */ - if (cxx_dialect >= cxx14 - && INDIRECT_REF_P (retval) - && REF_PARENTHESIZED_P (retval)) - { - retval = TREE_OPERAND (retval, 0); - while (TREE_CODE (retval) == NON_LVALUE_EXPR - || TREE_CODE (retval) == NOP_EXPR) - retval = TREE_OPERAND (retval, 0); - gcc_assert (TREE_CODE (retval) == ADDR_EXPR); - retval = TREE_OPERAND (retval, 0); - } + retval = maybe_undo_parenthesized_ref (retval); /* Under C++11 [12.8/32 class.copy], a returned lvalue is sometimes treated as an rvalue for the purposes of overload resolution to diff --git a/gcc/testsuite/g++.dg/cpp1y/paren2.C b/gcc/testsuite/g++.dg/cpp1y/paren2.C new file mode 100644 index 0000000..56736b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/paren2.C @@ -0,0 +1,26 @@ +// PR c++/69736 +// { dg-do compile { target c++14 } } + +void fn1(bool = true) +{ + (fn1)(); +} + +template +void fn2() +{ + (fn1)(); +} + +struct X +{ + static void fn3(bool = true) + { + (X::fn3)(); + } + + void fn4(bool = true) + { + (X::fn4)(); + } +};