From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32612 invoked by alias); 15 Feb 2013 01:17:51 -0000 Received: (qmail 32600 invoked by uid 22791); 15 Feb 2013 01:17:50 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,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; Fri, 15 Feb 2013 01:17:44 +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 r1F1Hixu012680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Feb 2013 20:17:44 -0500 Received: from [10.3.113.52] (ovpn-113-52.phx2.redhat.com [10.3.113.52]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1F1HfaL004852 for ; Thu, 14 Feb 2013 20:17:43 -0500 Message-ID: <511D8CB5.9040603@redhat.com> Date: Fri, 15 Feb 2013 01:17:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55003 (wrong error with auto template static data member) Content-Type: multipart/mixed; boundary="------------060303030000090707000000" 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: 2013-02/txt/msg00754.txt.bz2 This is a multi-part message in MIME format. --------------060303030000090707000000 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 279 Normally we defer instantiation of the initializer of a static data member of a template class until it is actually needed. If we need it for deducing the type of the variable, we can go ahead and instantiate it at that point. Tested x86_64-pc-linux-gnu, applying to trunk. --------------060303030000090707000000 Content-Type: text/x-patch; name="55003.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="55003.patch" Content-length: 1319 commit fe74d7110cbaf9ccf153e2950eee04fe0907a988 Author: Jason Merrill Date: Thu Feb 14 12:39:19 2013 -0500 PR c++/55003 * decl.c (cp_finish_decl): Force instantiation of an auto static data member. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index eb6c490..3d63389 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6111,6 +6111,15 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, tree d_init; if (init == NULL_TREE) { + if (DECL_TEMPLATE_INSTANTIATION (decl) + && !DECL_TEMPLATE_INSTANTIATED (decl)) + { + /* init is null because we're deferring instantiating the + initializer until we need it. Well, we need it now. */ + instantiate_decl (decl, /*defer_ok*/true, /*expl*/false); + return; + } + error ("declaration of %q#D has no initializer", decl); TREE_TYPE (decl) = error_mark_node; return; diff --git a/gcc/testsuite/g++.dg/cpp0x/auto37.C b/gcc/testsuite/g++.dg/cpp0x/auto37.C new file mode 100644 index 0000000..f4b2904 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto37.C @@ -0,0 +1,14 @@ +// PR c++/55003 +// { dg-do compile { target c++11 } } + +template +struct A { + static const auto t + = (typename T::type)42; +}; + +struct X { + typedef int type; +}; + +A a; --------------060303030000090707000000--