From patchwork Sun Oct 9 14:27:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Fromreide X-Patchwork-Id: 118588 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 47F97B70D1 for ; Mon, 10 Oct 2011 01:28:00 +1100 (EST) Received: (qmail 32096 invoked by alias); 9 Oct 2011 14:27:57 -0000 Received: (qmail 32084 invoked by uid 22791); 9 Oct 2011 14:27:55 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_20, RP_MATCHES_RCVD, TW_CX X-Spam-Check-By: sourceware.org Received: from mail.lysator.liu.se (HELO mail.lysator.liu.se) (130.236.254.3) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 09 Oct 2011 14:27:35 +0000 Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 8094240003; Sun, 9 Oct 2011 16:27:33 +0200 (CEST) Received: from [192.168.0.101] (user13.77-105-211.netatonce.net [77.105.211.13]) (using SSLv3 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 3266140008; Sun, 9 Oct 2011 16:27:33 +0200 (CEST) Subject: [C++ Patch] Trailing comma in enum From: Magnus Fromreide To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Date: Sun, 09 Oct 2011 16:27:32 +0200 Message-ID: <1318170453.2344.8.camel@sara> 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 Hi. As I understand it C++11 allows trailing commas in enum definitions. Thus I think the following little patch should be included. On a side note I have to say that the effects of pedwarn_cxx98 are unexpected, especially in light of the comment above the function body. /MF 2011-10-09 Magnus Fromreide * gcc/cp/parser.c (cp_parser_enumerator_list): Do not warn about trailing commas in C++0x mode. * gcc/testsuite/g++.dg/cpp0x/enum21a.C: Test that enum x { y, } do generate a pedwarning in c++98-mode. * gcc/testsuite/g++.dg/cpp0x/enum21b.C: Test that enum x { y, } don't generate a pedwarning in c++0x-mode. Index: gcc/testsuite/g++.dg/cpp0x/enum21a.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/enum21a.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/enum21a.C (revision 0) @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-pedantic" } + +enum x { y, }; // { dg-warning "comma at end of enumerator list" } Index: gcc/testsuite/g++.dg/cpp0x/enum21b.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/enum21b.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/enum21b.C (revision 0) @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-pedantic -std=c++0x" } + +enum x { y, }; Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 179711) +++ gcc/cp/parser.c (working copy) @@ -13444,6 +13444,7 @@ cp_parser_elaborated_type_specifier (cp_parser* pa enum-specifier: enum-head { enumerator-list [opt] } + enum-head { enumerator-list , } [C++0x] enum-head: enum-key identifier [opt] enum-base [opt] @@ -13463,6 +13464,8 @@ cp_parser_elaborated_type_specifier (cp_parser* pa GNU Extensions: enum-key attributes[opt] identifier [opt] enum-base [opt] { enumerator-list [opt] }attributes[opt] + enum-key attributes[opt] identifier [opt] enum-base [opt] + { enumerator-list, }attributes[opt] [C++0x] Returns an ENUM_TYPE representing the enumeration, or NULL_TREE if the token stream isn't an enum-specifier after all. */ @@ -13802,8 +13805,9 @@ cp_parser_enumerator_list (cp_parser* parser, tree /* If the next token is a `}', there is a trailing comma. */ if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE)) { - if (!in_system_header) - pedwarn (input_location, OPT_pedantic, "comma at end of enumerator list"); + if (cxx_dialect < cxx0x && !in_system_header) + pedwarn (input_location, OPT_pedantic, + "comma at end of enumerator list"); break; } }