From patchwork Fri Mar 29 22:29:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Dos Reis X-Patchwork-Id: 232496 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 00B582C00AF for ; Sat, 30 Mar 2013 09:29:41 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=ao+tCWVOEp3QA4K1Yso6KKmYKN/OHG7r0t3uTYPIPq3oZJ+SWI 2vC1OjTi07aivqsA6o4x9IwNsDx82+E1nMPJe15W+6rZBW5cktuwpYJSK/3WlWnT IO28A6DNqq+T8ZwLSdent6Wtqp7yGxHTv76Ugr3w59nnvyFTSG2pwiV+M= 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:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=E6S67VxrJuwNo/msQmnjgEHXoAI=; b=yL+Z05AvcBjL9K5l8goI 7J/s/RDTEcbmpcpVPP8CrdaP7bgqK6ClGsdHHIll+XmmxRKCXNh3YSM1OzSFo8cx C8tzGW8n2Wu7Q2I/x64jrJY31yKsZ7fUaGzetBbrojOMNkov3DaqJ/xGvK01C5SQ ci2rhlyI9mRnoUzij3mT1HU= Received: (qmail 30386 invoked by alias); 29 Mar 2013 22:29:28 -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 30359 invoked by uid 89); 29 Mar 2013 22:29:15 -0000 X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from www.axiomatics.org (HELO mail.axiomatics.org) (66.228.53.191) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 29 Mar 2013 22:29:13 +0000 Received: by mail.axiomatics.org (Postfix, from userid 1000) id 28AE0ED51; Fri, 29 Mar 2013 17:29:10 -0500 (CDT) From: Gabriel Dos Reis To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: [var-template] Accept variable template declaration Date: Fri, 29 Mar 2013 17:29:10 -0500 Message-ID: <87ip49et6x.fsf@euclid.axiomatics.org> Lines: 74 MIME-Version: 1.0 This patch lets us accept declarations of constexpr variable templates. Actual semantics processing of specialization is subject of follow up patches. The patch represents a variable template as a variable temploid whose scope is a namespace, or member template that generates a static data member. Applied to var-template branch. -- Gaby 2013-03-29 Gabriel Dos Reis * cp-tree.h (variable_template_p): New. * pt.c (check_template_variable): Accept variable temploids at non-class scope. (push_template_decl_real): The current instantiation of a template can be a VAR_DECL. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 197248) +++ gcc/cp/cp-tree.h (working copy) @@ -4926,6 +4926,18 @@ return TREE_TYPE (type_of_this_parm (fntype)); } +/* True if T designates a variable template declaration. */ +inline bool +variable_template_p (tree t) +{ + if (TREE_CODE (t) != TEMPLATE_DECL + || !(DECL_NAMESPACE_SCOPE_P (t) || DECL_MEMBER_TEMPLATE_P (t))) + return false; + if (tree r = DECL_TEMPLATE_RESULT (t)) + return VAR_P (r); + return false; +} + /* A parameter list indicating for a function with no parameters, e.g "int f(void)". */ extern cp_parameter_declarator *no_parameters; Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 197248) +++ gcc/cp/pt.c (working copy) @@ -2270,9 +2270,11 @@ { tree ctx = CP_DECL_CONTEXT (decl); int wanted = num_template_headers_for_class (ctx); - if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx)) - permerror (DECL_SOURCE_LOCATION (decl), - "%qD is not a static data member of a class template", decl); + if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx)) { + if (cxx_dialect < cxx1y) + permerror (DECL_SOURCE_LOCATION (decl), + "%qD is not a static data member of a class template", decl); + } else if (template_header_count > wanted) { pedwarn (DECL_SOURCE_LOCATION (decl), 0, @@ -4616,6 +4618,10 @@ && TYPE_DECL_ALIAS_P (decl)) /* alias-declaration */ gcc_assert (!DECL_ARTIFICIAL (decl)); + else if (VAR_P (decl)) { + if (!DECL_DECLARED_CONSTEXPR_P (decl)) + error ("template declaration of non-constexpr variable %qD", decl); + } else { error ("template declaration of %q#D", decl);