From patchwork Tue Nov 22 16:40:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 127127 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]) by ozlabs.org (Postfix) with SMTP id 5FC1E1007D1 for ; Wed, 23 Nov 2011 03:41:02 +1100 (EST) Received: (qmail 19413 invoked by alias); 22 Nov 2011 16:40:55 -0000 Received: (qmail 19070 invoked by uid 22791); 22 Nov 2011 16:40:52 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Tue, 22 Nov 2011 16:40:35 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAMGeZ4A027770 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Nov 2011 11:40:35 -0500 Received: from localhost (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pAMGeXRC001038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Nov 2011 11:40:34 -0500 Received: by localhost (Postfix, from userid 500) id 8F6BD29C12D; Tue, 22 Nov 2011 17:40:32 +0100 (CET) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH] PR c++/51143 - Alias template allows class definition References: <4ECBABD8.7060305@redhat.com> X-URL: http://www.redhat.com Date: Tue, 22 Nov 2011 17:40:32 +0100 In-Reply-To: <4ECBABD8.7060305@redhat.com> (Jason Merrill's message of "Tue, 22 Nov 2011 09:04:08 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 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 Jason Merrill writes: > Do we have a test for allowing a class definition in a non-template > alias definition? If not, please add that too. Good catch. I have a test for that in the test file. > OK with that change. Thanks. Below is what I have tested and checked in. From: Dodji Seketeli Date: Mon, 21 Nov 2011 22:31:10 +0100 Subject: [PATCH] PR c++/51143 - Alias template allows class definition gcc/cp PR c++/51143 * parser.c (cp_parser_alias_declaration): Don't allow type definition in templates. gcc/testsuite PR c++/51143 * g++.dg/cpp0x/alias-decl-16.C: New test. --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/parser.c | 29 ++++++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/cpp0x/alias-decl-16.C | 28 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 0 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-16.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c083144..290538c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-11-22 Dodji Seketeli + + PR c++/51143 + * parser.c (cp_parser_alias_declaration): Don't allow type + definition in templates. + 2011-11-20 Jason Merrill * pt.c (tsubst_pack_expansion): Fix SFINAE. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f839112..744ad3f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -14940,6 +14940,7 @@ cp_parser_alias_declaration (cp_parser* parser) cp_declarator *declarator; cp_decl_specifier_seq decl_specs; bool member_p; + const char *saved_message = NULL; /* Look for the `using' keyword. */ cp_parser_require_keyword (parser, RID_USING, RT_USING); @@ -14948,7 +14949,35 @@ cp_parser_alias_declaration (cp_parser* parser) attributes = cp_parser_attributes_opt (parser); cp_parser_require (parser, CPP_EQ, RT_EQ); + /* Now we are going to parse the type-id of the declaration. */ + + /* + [dcl.type]/3 says: + + "A type-specifier-seq shall not define a class or enumeration + unless it appears in the type-id of an alias-declaration (7.1.3) that + is not the declaration of a template-declaration." + + In other words, if we currently are in an alias template, the + type-id should not define a type. + + So let's set parser->type_definition_forbidden_message in that + case; cp_parser_check_type_definition (called by + cp_parser_class_specifier) will then emit an error if a type is + defined in the type-id. */ + if (parser->num_template_parameter_lists) + { + saved_message = parser->type_definition_forbidden_message; + parser->type_definition_forbidden_message = + G_("types may not be defined in alias template declarations"); + } + type = cp_parser_type_id (parser); + + /* Restore the error message if need be. */ + if (parser->num_template_parameter_lists) + parser->type_definition_forbidden_message = saved_message; + cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON); if (cp_parser_error_occurred (parser)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5c1fb00..8d6f16a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-11-22 Dodji Seketeli + + PR c++/51143 + * g++.dg/cpp0x/alias-decl-16.C: New test. + 2011-11-20 Joey Ye * gcc.dg/volatile-bitfields-1.c: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-16.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-16.C new file mode 100644 index 0000000..d66660a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-16.C @@ -0,0 +1,28 @@ +// Origin PR c++/51143 +// { dg-options "-std=c++11" } + +using A0 = struct B0 { void f() {} }; + +template +using A1 = + struct B1 { // { dg-error "types may not be defined in alias template" } + static auto constexpr value = N; + }; + +A1<0> a1; + +template +using A2 = + struct B2 { // { dg-error "types may not be defined in alias template" } + void f(T){} + }; + +A2 a2; + +template +using A3 = + enum B3 {b = 0;}; //{ dg-error "types may not be defined in alias template" } + +A3 a3; + +int main() { }