From patchwork Wed Feb 13 05:13:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1040946 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-495976-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="uUA8pQSZ"; 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 43znkF6PlTz9s7h for ; Wed, 13 Feb 2019 16:13:52 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=OhI98aBbO6WInFxqBP3+xvJUtMf6GwKZ8pk0KgkxopGuEeFQhMLe8 FxwPy0hDvvaojY8Wu+UB8pHgjUenUhASRWLYHQYDc0mhpva1OrQc3jQwJt7QfpRs BC8t+aRwvlSX/u++26d3/wKoM2AwVoMYvorIiA7rVHOowdXiLhzyys= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=blIkx6ZQplmwQg7+60o4dEMRwFw=; b=uUA8pQSZ+joXveB3rfhm BnTrDNmlOQSwd9QB0ASMBl4o/KLkv9nUKPMjcjYtmNEOdugtc4MdZhZjeLRGdOlr hq8JRPduPL8BIlSUoFh4QcAK2I9VlkVdf8niy2/KCk+JnfpMNCsX9n51EzDgYbHC IG+SyS5jyeFqC1CtGMY+fzM= Received: (qmail 54380 invoked by alias); 13 Feb 2019 05:13:46 -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 54370 invoked by uid 89); 13 Feb 2019 05:13:45 -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, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Feb 2019 05:13:44 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A259E81F19 for ; Wed, 13 Feb 2019 05:13:43 +0000 (UTC) Received: from redhat.com (ovpn-125-179.rdu2.redhat.com [10.10.125.179]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36D2B1000239; Wed, 13 Feb 2019 05:13:43 +0000 (UTC) Date: Wed, 13 Feb 2019 00:13:42 -0500 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/89297 - ICE with OVERLOAD in template Message-ID: <20190213051342.GT3884@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Here we ICE because we're in a template and the constructor contains an OVERLOAD, so calling check_narrowing -> maybe_constant_value crashes. check_narrowing deliberately calls maybe_constant_value and not fold_non_dependent_expr so as to avoid instantiating expressions twice. So let's use instantiate_non_dependent_expr_sfinae to deal with the OVERLOAD; fold_non_dependent_expr always calls maybe_constant_value and we can avoid that call. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-02-12 Marek Polacek PR c++/89297 - ICE with OVERLOAD in template. * semantics.c (finish_compound_literal): Call instantiate_non_dependent_expr_sfinae. * g++.dg/cpp0x/initlist113.C: New test. diff --git gcc/cp/semantics.c gcc/cp/semantics.c index 786f18ab0c8..e89a38d3cba 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -2826,9 +2826,13 @@ finish_compound_literal (tree type, tree compound_literal, return error_mark_node; compound_literal = reshape_init (type, compound_literal, complain); if (SCALAR_TYPE_P (type) - && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal) - && !check_narrowing (type, compound_literal, complain)) - return error_mark_node; + && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)) + { + compound_literal + = instantiate_non_dependent_expr_sfinae (compound_literal, complain); + if (!check_narrowing (type, compound_literal, complain)) + return error_mark_node; + } if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE) { diff --git gcc/testsuite/g++.dg/cpp0x/initlist113.C gcc/testsuite/g++.dg/cpp0x/initlist113.C new file mode 100644 index 00000000000..0b7e7ff606a --- /dev/null +++ gcc/testsuite/g++.dg/cpp0x/initlist113.C @@ -0,0 +1,11 @@ +// PR c++/89297 +// { dg-do compile { target c++11 } } + +int id(int v) { return v; } +float id(float v) { return v; } + +template +int foo(int v) +{ + return int{id(v)}; +}