From patchwork Wed May 31 17:10:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 769287 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 3wdH7k22hHz9ryv for ; Thu, 1 Jun 2017 03:11:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Toh3ArxL"; 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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=e0pL69WnWoyW0LLbKxdzAt9suvhvqv8rFezwLcLkyhl0E3 NaS+lii2zfEWRMMpDFY53pZ70K6QeXRsSP8c+SYW4jTvOMI3G7yZA3noB8WcocQx YPKeizPjDWear4Rg8MMaG86iBu3FybZqA9EmhlqhXN1CiMca8PcMMdjPtHyMQ= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=ODQpro0SvAfQlfLZWWG2B9ZLuhc=; b=Toh3ArxLvl9ufmPX3qfx UIFmIUMXUumt9zKvhDkvyn4gcqW94BThiCFYzudyZ9vlZl6A6b3sqTC7Y1jmSb6a VwauKuRZ9Ugsx0I8i29W7oUetzaWF1nPDrr3oIXjB6sgIu+U6Zi83FkRBKiTVi8h XW2hqel1DKeQMbj9iEFqBQQ= Received: (qmail 117578 invoked by alias); 31 May 2017 17:11: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 117438 invoked by uid 89); 31 May 2017 17:11:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f176.google.com Received: from mail-io0-f176.google.com (HELO mail-io0-f176.google.com) (209.85.223.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 May 2017 17:11:14 +0000 Received: by mail-io0-f176.google.com with SMTP id k91so19984914ioi.1 for ; Wed, 31 May 2017 10:11:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=4/3R1pZxrB0hSSWP9AKhhBaC3UUrKLwGXt6arat0XbM=; b=EQ5lPpnz/hBcwRnSk5HhAvuNP6nsklM9w5yFjQDZVL3a5j+9tBTpkYuIDb7rLdvxgw nspaQym/OPgB+NnSuN9DZz8E6DPqbH276ZkBDGdiZPnjjyG8AzfdC8Jv9mNqRZcwMAgu DC7C1GcBvBMqw3gglAeYUKMxpTB748qfIGXABftSZSvZBjUIMSq+O5D+n3ZJK3352X/9 CGN2PO/zdDO+G0i2hqmgfQLm639KVn8SUkNswpM7Njs0++2DrXSvK0fVMVfPiEZMjhjW UYfKeoLSaoYlqxrEvNoLcE77kLz+3FVHLxsqqeL7GFg7NjQx3etTMg+Nbh9t6cvkMPbE p7ew== X-Gm-Message-State: AODbwcBJj5/Y5f3wXWbS/OSQzgrc6HgwxD3Fc1K9k938v7bfXmwdHDLP CzbhEZZbSMeRG+QSkDsxaNwm9UVSN+5PLKk= X-Received: by 10.107.25.203 with SMTP id 194mr22773642ioz.182.1496250676833; Wed, 31 May 2017 10:11:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.6.226 with HTTP; Wed, 31 May 2017 10:10:55 -0700 (PDT) From: Jason Merrill Date: Wed, 31 May 2017 13:10:55 -0400 Message-ID: Subject: C++ PATCH for c++/80840, ICE with constexpr and reference template parm To: gcc-patches List X-IsSubscribed: yes In convert_nontype_argument to reference type we were inappropriately checking value_dependent_expression_p on an expression that might be a VAR_DECL and might be a TEMPLATE_PARM_INDEX of reference type. It's inappropriate in the former case because we don't care about the value of the object, only its address; we only want to test for the latter case. Tested x86_64-pc-linux-gnu, applying to trunk. commit 388ec8de844dda6785d55daef0fffc90eb49118c Author: Jason Merrill Date: Tue May 30 21:38:17 2017 -0400 PR c++/80840 - ICE with constexpr and reference * pt.c (convert_nontype_argument): Don't test whether a decl is value-dependent when binding to a reference. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c1a8885..8239a3e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6749,7 +6749,11 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) } } - if (!value_dependent_expression_p (expr)) + if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE + && value_dependent_expression_p (expr)) + /* OK, dependent reference. We don't want to ask whether a DECL is + itself value-dependent, since what we want here is its address. */; + else { if (!DECL_P (expr)) { @@ -6771,8 +6775,11 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) return NULL_TREE; } - expr = build_nop (type, build_address (expr)); + expr = build_address (expr); } + + if (!same_type_p (type, TREE_TYPE (expr))) + expr = build_nop (type, expr); } /* [temp.arg.nontype]/5, bullet 4 diff --git a/gcc/testsuite/g++.dg/template/ref10.C b/gcc/testsuite/g++.dg/template/ref10.C new file mode 100644 index 0000000..60e91d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ref10.C @@ -0,0 +1,13 @@ +// PR c++/80840 +// { dg-do compile { target c++11 } } + +template +struct Just; + +template +struct Number { + static constexpr double value = X; + using result = Just; +}; + +int main() {}