From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4707 invoked by alias); 16 Aug 2012 22:15:36 -0000 Received: (qmail 4680 invoked by uid 22791); 16 Aug 2012 22:15:34 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Aug 2012 22:15:17 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7GMFHmN000725 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 16 Aug 2012 18:15:17 -0400 Received: from localhost (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7GMFF8n017009 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 16 Aug 2012 18:15:16 -0400 Received: by localhost (Postfix, from userid 500) id 53ADB29C04D; Fri, 17 Aug 2012 00:15:15 +0200 (CEST) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: [PATCH] PR c++/53540 - using fails to be equivalent to typedef X-URL: http://www.redhat.com Date: Thu, 16 Aug 2012 22:15:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 X-SW-Source: 2012-08/txt/msg01111.txt.bz2 Hello, In the example of this problem report, during the substituting of int into 'function', tsubst_aggr_type fails for the alias ctxt1. This is because TYPE_TEMPLATE_INFO looks for the TEMPLATE_INFO of the ctxt1 alias at the wrong place and was wrongly finding it to be NULL. Namely, it was looking for it in the DECL_TEMPLATE_INFO of the declaration of the type -- as if ctxt1 was an alias template specialization -- rather than looking of it in its CLASSTYPE_TEMPLATE_INFO. Fixed thus. The second hunk of the patch is just to prevent the compiler from crashing when primary_template_instantiation_p is passed an alias of a class template instantiation. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/cp * cp-tree.h (TYPE_TEMPLATE_INFO): For an alias that is not an instance of alias template, don't look for its TEMPLATE_INFO in its declaration. * pt.c (primary_template_instantiation_p): Don't crash on an alias that is not an instance of a template. gcc/testsuite/ * g++.dg/cpp0x/alias-decl-21.C: New test. --- gcc/cp/cp-tree.h | 4 ++-- gcc/cp/pt.c | 1 + gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 44f3ac1..64a8830 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2634,8 +2634,8 @@ extern void decl_shadowed_for_var_insert (tree, tree); template info for the alias template, not the one (if any) for the template of the underlying type. */ #define TYPE_TEMPLATE_INFO(NODE) \ - (TYPE_ALIAS_P (NODE) \ - ? ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ + ((TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE))) \ + ? (DECL_LANG_SPECIFIC (TYPE_NAME (NODE)) \ ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE)) \ : NULL_TREE) \ : ((TREE_CODE (NODE) == ENUMERAL_TYPE) \ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ad81bab..3163bd4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2854,6 +2854,7 @@ primary_template_instantiation_p (const_tree t) else if (TYPE_P (t) && TYPE_TEMPLATE_INFO (t) && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t)) + && DECL_LANG_SPECIFIC (TYPE_NAME (t)) && DECL_TEMPLATE_INSTANTIATION (TYPE_NAME (t))) return true; return false; diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C new file mode 100644 index 0000000..b68fa93 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C @@ -0,0 +1,24 @@ +// Origin: PR c++/53540 +// { dg-do compile { target c++11 } } + +template +struct context +{ + typedef int type; +}; + +template +void function() +{ + using ctx1 = context; + typename ctx1::type f1; + + typedef context ctx2; + typename ctx2::type f2; +} + +int main() +{ + function(); +} + -- Dodji