From patchwork Tue Jul 9 17:38:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 257844 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 077592C0089 for ; Wed, 10 Jul 2013 03:39:58 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=EeaFS6pKQJkd/naf4Cp1PRqnpcRNaeRf8v9yrMjfFYakeO AB0QiGJCTKmxFYVRhg6vnN45aaezeMCLA99XyBQhBgsxLLlHhz3s3IwQGAE5tyYy 1WS9z52xYCwHCKdgvitotk1yyf7EI2fgImupeL0Cd4ZfZM1ErkF5YWCu27zRA= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=kImQ0pWnHulUY8/V7iXUgOvooOc=; b=K11B6D9es9xw0XiRPgnz WLAbc2k9CZc06XV1xdoNjeecEH6ajNDhReC/0bQU4V/oGMSQJaSzEQy4vqxHVLvY zRSycreeGyficg9frcgGCXL+MoYiDcvfc7QHUazCPg3EOSKFAZcVZ+jTBvrDhT7V Xbhc1gxnFurzyvgum5vq6Ug= Received: (qmail 2283 invoked by alias); 9 Jul 2013 17:38:59 -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 2249 invoked by uid 89); 9 Jul 2013 17:38:59 -0000 X-Spam-SWARE-Status: No, score=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 09 Jul 2013 17:38:58 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r69HcuBk030606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Jul 2013 13:38:57 -0400 Received: from [10.3.113.19] ([10.3.113.19]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r69Hcs5C009611 for ; Tue, 9 Jul 2013 13:38:55 -0400 Message-ID: <51DC4AAD.5040000@redhat.com> Date: Tue, 09 Jul 2013 13:38:53 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/57545 (ICE with -g and non-type template parameter) X-Virus-Found: No This is an instance where we were failing to canonicalize a template argument: for an integer constant, we need to make sure that it has the type of the template parameter, rather than possibly a typedef local to another template. Tested x86_64-pc-linux-gnu, applying to trunk, 4.8, 4.7. commit 1f06a84c5f6716cbc23498eeb9a4dfff1203b516 Author: Jason Merrill Date: Tue Jul 9 02:26:39 2013 -0400 PR c++/57545 * pt.c (convert_nontype_argument) [INTEGER_CST]: Force the argument to have the exact type of the parameter. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 23229a9..877d3b7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5620,6 +5620,10 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) else return NULL_TREE; } + + /* Avoid typedef problems. */ + if (TREE_TYPE (expr) != type) + expr = fold_convert (type, expr); } /* [temp.arg.nontype]/5, bullet 2 diff --git a/gcc/testsuite/g++.dg/debug/template2.C b/gcc/testsuite/g++.dg/debug/template2.C new file mode 100644 index 0000000..9f5bcd9 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/template2.C @@ -0,0 +1,14 @@ +// PR c++/57545 + +template +struct array { + T data[N]; +}; + +template +struct derived { + typedef long unsigned int size_type; + static const size_type n = 42; + + array a; +};