From patchwork Fri Jan 18 03:58:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1027103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-494274-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qf5+WHIA"; dkim-atps=neutral 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 43gnH55Pptz9sDr for ; Fri, 18 Jan 2019 14:58:24 +1100 (AEDT) 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:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=C61hGJNMHPzEMCib 8zneDiG5SJo59D27w+GEQuKh+FyWoYl+luJ555pZD3u3FrPLw/4pGlG/NY4E7Okb RBFgmH3H62NP566viZrmjoycgHNRkp+JtXwvml6at1lnLzAPHlrGCC07UJBkcifT Be1UNuen/WGQ93K7iluEfhbheFs= 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:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=4GwNh0WJxr1/uCtszIR1GG nNXVU=; b=qf5+WHIAO5Q3pY9ARARTwP9/XabBpufodbjE8VmuAYwb+duhjFdh4o pJwAioSpAHSzxkA8H3NXUT4gL2yVELZx4yovg3OGp/Omz+Ic/hpaN6l0WaOydl0e Yz+Vv1TunXKYCb7BM9c3yW2EtOloOCwvHxq6tzaKHj/Whx/3vyp3U= Received: (qmail 130456 invoked by alias); 18 Jan 2019 03:58:17 -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 130443 invoked by uid 89); 18 Jan 2019 03:58:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt1-f194.google.com Received: from mail-qt1-f194.google.com (HELO mail-qt1-f194.google.com) (209.85.160.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Jan 2019 03:58:14 +0000 Received: by mail-qt1-f194.google.com with SMTP id l12so13844520qtf.8 for ; Thu, 17 Jan 2019 19:58:14 -0800 (PST) Received: from orpheus.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id c202sm49655309qkb.19.2019.01.17.19.58.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 19:58:11 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/86205 - ICE with ?: of throw and template-id. Date: Thu, 17 Jan 2019 22:58:09 -0500 Message-Id: <20190118035809.18783-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes My patch for 64372 removed a bogus lvalue-rvalue conversion for one arm of a ?: expression where the other arm is a throw. But we still need to require any overload to be resolved, even though we aren't getting that from decay_conversion anymore. Tested x86_64-pc-linux-gnu, applying to trunk. * pt.c (resolve_nondeduced_context_or_error): Split out from... * typeck.c (decay_conversion): ...here. * call.c (build_conditional_expr_1): Use it. --- gcc/cp/cp-tree.h | 1 + gcc/cp/call.c | 13 +++++++++++++ gcc/cp/pt.c | 15 +++++++++++++++ gcc/cp/typeck.c | 8 +------- gcc/testsuite/g++.dg/cpp0x/cond2.C | 14 ++++++++++++++ gcc/cp/ChangeLog | 5 +++++ 6 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/cond2.C base-commit: 978cfaf23536dc8eefd4fe79c38f564de931e1af diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 5cc8f88d522..23d4a0e3c69 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6831,6 +6831,7 @@ extern tree get_template_innermost_arguments (const_tree); extern tree get_template_argument_pack_elems (const_tree); extern tree get_function_template_decl (const_tree); extern tree resolve_nondeduced_context (tree, tsubst_flags_t); +extern tree resolve_nondeduced_context_or_error (tree, tsubst_flags_t); extern hashval_t iterative_hash_template_arg (tree arg, hashval_t val); extern tree coerce_template_parms (tree, tree, tree); extern tree coerce_template_parms (tree, tree, tree, tsubst_flags_t); diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 4f04b610004..c639f5f23e8 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5067,6 +5067,19 @@ build_conditional_expr_1 (const op_location_t &loc, arg3_type = unlowered_expr_type (arg3); if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type)) { + /* 'void' won't help in resolving an overloaded expression on the + other side, so require it to resolve by itself. */ + if (arg2_type == unknown_type_node) + { + arg2 = resolve_nondeduced_context_or_error (arg2, complain); + arg2_type = TREE_TYPE (arg2); + } + if (arg3_type == unknown_type_node) + { + arg3 = resolve_nondeduced_context_or_error (arg3, complain); + arg3_type = TREE_TYPE (arg3); + } + /* [expr.cond] One of the following shall hold: diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e4f76478f54..48c180cc13b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -21147,6 +21147,21 @@ resolve_nondeduced_context (tree orig_expr, tsubst_flags_t complain) return orig_expr; } +/* As above, but error out if the expression remains overloaded. */ + +tree +resolve_nondeduced_context_or_error (tree exp, tsubst_flags_t complain) +{ + exp = resolve_nondeduced_context (exp, complain); + if (type_unknown_p (exp)) + { + if (complain & tf_error) + cxx_incomplete_type_error (exp, TREE_TYPE (exp)); + return error_mark_node; + } + return exp; +} + /* Subroutine of resolve_overloaded_unification; does deduction for a single overload. Fills TARGS with any deduced arguments, or error_mark_node if different overloads deduce different arguments for a given parm. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index fc61991de35..2fff2625bee 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2009,13 +2009,7 @@ decay_conversion (tree exp, if (type == error_mark_node) return error_mark_node; - exp = resolve_nondeduced_context (exp, complain); - if (type_unknown_p (exp)) - { - if (complain & tf_error) - cxx_incomplete_type_error (exp, TREE_TYPE (exp)); - return error_mark_node; - } + exp = resolve_nondeduced_context_or_error (exp, complain); code = TREE_CODE (type); diff --git a/gcc/testsuite/g++.dg/cpp0x/cond2.C b/gcc/testsuite/g++.dg/cpp0x/cond2.C new file mode 100644 index 00000000000..ec82dee10b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/cond2.C @@ -0,0 +1,14 @@ +// PR c++/86205 +// { dg-do compile { target c++11 } } + +bool b; + +template < class T > int f () +{ + return 0; +} + +template < class T > auto g () -> decltype (b ? f < int > : throw 0) +{ + return b ? f : throw 0; +} diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 01a57601f4c..3fb1a895b5a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2019-01-17 Jason Merrill + PR c++/86205 - ICE with ?: of throw and template-id. + * pt.c (resolve_nondeduced_context_or_error): Split out from... + * typeck.c (decay_conversion): ...here. + * call.c (build_conditional_expr_1): Use it. + PR c++/86740, ICE with constexpr if and nested generic lambdas. * tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR.