From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111580 invoked by alias); 11 Dec 2018 21:05:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 111557 invoked by uid 89); 11 Dec 2018 21:05:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,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; Tue, 11 Dec 2018 21:05:10 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 051D4C056824 for ; Tue, 11 Dec 2018 21:05:09 +0000 (UTC) Received: from redhat.com (unknown [10.20.4.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97346608F6; Tue, 11 Dec 2018 21:05:08 +0000 (UTC) Date: Tue, 11 Dec 2018 21:05:00 -0000 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: C++ PATCH for c++/88216, ICE with class type in non-type template parameter Message-ID: <20181211210506.GX21364@redhat.com> References: <20181210195215.GP21364@redhat.com> <7b54d664-f7cb-3a45-bc40-6d62f29ceb5a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7b54d664-f7cb-3a45-bc40-6d62f29ceb5a@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2018-12/txt/msg00744.txt.bz2 On Tue, Dec 11, 2018 at 10:48:17AM -0500, Jason Merrill wrote: > On 12/10/18 2:52 PM, Marek Polacek wrote: > > + if (processing_template_decl && value_dependent_expression_p (expr)) > > You don't need to check processing_template_decl before > value_dependent_expression_p. Ok. > I would lean toward checking for value-dependence in > convert_nontype_argument, which already does that a lot. Enough, actually, > that perhaps we should remember the result in a local variable. I've moved the call, but I didn't add a local variable for the result, because I was afraid that, since EXPR is being modified on some of the codepaths, its value-dependent-ness (is that a term?) may change. Thanks, Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-12-11 Marek Polacek PR c++/88216 - ICE with class type in non-type template parameter. * mangle.c (write_expression): Handle TARGET_EXPR and VIEW_CONVERT_EXPR. * pt.c (convert_nontype_argument): Don't call get_template_parm_object for value-dependent expressions. * g++.dg/cpp2a/nontype-class9.C: New test. diff --git gcc/cp/mangle.c gcc/cp/mangle.c index 64415894bc5..56247883010 100644 --- gcc/cp/mangle.c +++ gcc/cp/mangle.c @@ -2836,13 +2836,21 @@ write_expression (tree expr) { enum tree_code code = TREE_CODE (expr); + if (TREE_CODE (expr) == TARGET_EXPR) + { + expr = TARGET_EXPR_INITIAL (expr); + code = TREE_CODE (expr); + } + /* Skip NOP_EXPR and CONVERT_EXPR. They can occur when (say) a pointer argument is converted (via qualification conversions) to another type. */ while (CONVERT_EXPR_CODE_P (code) || location_wrapper_p (expr) /* Parentheses aren't mangled. */ || code == PAREN_EXPR - || code == NON_LVALUE_EXPR) + || code == NON_LVALUE_EXPR + || (code == VIEW_CONVERT_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX)) { expr = TREE_OPERAND (expr, 0); code = TREE_CODE (expr); diff --git gcc/cp/pt.c gcc/cp/pt.c index 8560e588593..3b378ee9ff4 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -7123,7 +7123,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) { /* Replace the argument with a reference to the corresponding template parameter object. */ - expr = get_template_parm_object (expr, complain); + if (!value_dependent_expression_p (expr)) + expr = get_template_parm_object (expr, complain); if (expr == error_mark_node) return NULL_TREE; } diff --git gcc/testsuite/g++.dg/cpp2a/nontype-class9.C gcc/testsuite/g++.dg/cpp2a/nontype-class9.C new file mode 100644 index 00000000000..737f712be47 --- /dev/null +++ gcc/testsuite/g++.dg/cpp2a/nontype-class9.C @@ -0,0 +1,29 @@ +// PR c++/88216 +// { dg-do compile { target c++2a } } + +template struct same; +template struct same {}; + +struct T { }; + +template +struct U { }; + +template +void f (U) +{ + same s; + same s2; +} + +template +U u; + +T t; +U u2; + +void +g () +{ + f(u2); +}