From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31108 invoked by alias); 8 Apr 2016 11:51:09 -0000 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 Received: (qmail 31093 invoked by uid 89); 8 Apr 2016 11:51:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=qualification, Hx-languages-length:2721 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 08 Apr 2016 11:51:07 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FF7B6438E for ; Fri, 8 Apr 2016 11:51:06 +0000 (UTC) Received: from redhat.com (ovpn-204-18.brq.redhat.com [10.40.204.18]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u38Bp2dF010269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 8 Apr 2016 07:51:05 -0400 Date: Fri, 08 Apr 2016 11:51:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH to fix a part of c++/70513 (ICE-on-invalid with enums) Message-ID: <20160408115102.GI28445@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2016-04/txt/msg00398.txt.bz2 This is my attempt to fix at least a part of this PR. I haven't been able to come up with a fix that fixes the other part involving templates. We were ICEing on code such as struct S { enum E : int; enum S::E : int { foo } e; }; Clang rejects this with "extra qualification" error. When I modified the test to use structs rather than enums... struct T { struct U; struct T::U {}; }; ...I found out that we reject this with "extra qualification not allowed". So I think the enum case is missing a similar check that this patch adds. By the template part of this PR I mean that we ICE on template class D { enum D::A { foo } c; }; where clang++ says error: template specialization or definition requires a template parameter list corresponding to the nested type 'D' which I guess means that a valid code would have "" after "D". I thought num_template_headers_for_class and cp_parser_check_template_parameters would do the job here, but apparently something else needs to be used for this case. But I'm at my wits' end here. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-04-08 Marek Polacek PR c++/70513 * parser.c (cp_parser_enum_specifier): Check for extra qualification. * g++.dg/cpp0x/forw_enum12.C: New test. diff --git gcc/cp/parser.c gcc/cp/parser.c index 28e01af..dc0d1c8 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -17231,6 +17231,15 @@ cp_parser_enum_specifier (cp_parser* parser) type, prev_scope, nested_name_specifier); type = error_mark_node; } + /* If that scope is the scope where the declaration is being placed + the program is invalid. */ + else if (nested_name_specifier == prev_scope) + { + permerror (type_start_token->location, + "extra qualification not allowed"); + type = error_mark_node; + nested_name_specifier = NULL_TREE; + } } if (scoped_enum_p) diff --git gcc/testsuite/g++.dg/cpp0x/forw_enum12.C gcc/testsuite/g++.dg/cpp0x/forw_enum12.C index e69de29..906ba68 100644 --- gcc/testsuite/g++.dg/cpp0x/forw_enum12.C +++ gcc/testsuite/g++.dg/cpp0x/forw_enum12.C @@ -0,0 +1,29 @@ +// PR c++/70513 +// { dg-do compile { target c++11 } } + +struct S1 +{ + enum E : int; + enum S1::E : int { X } e; // { dg-error "extra qualification not allowed" } +}; + +struct S2 +{ + enum class E : int; + enum class S2::E : int { X } e; // { dg-error "extra qualification not allowed" } +}; + +struct S3 +{ + enum struct E : int; + enum struct S3::E : int { X } e; // { dg-error "extra qualification not allowed" } +}; + +struct S4 +{ + struct S5 + { + enum E : char; + enum S4::S5::E : char { X } e; // { dg-error "extra qualification not allowed" } + }; +}; Marek