From patchwork Tue Apr 10 15:06:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 896754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476146-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pn6ew8v4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40L9VX2hWqz9s08 for ; Wed, 11 Apr 2018 01:06:27 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=wPrgt/5betcXIHaJhBtO5guQ8JEOdieArppTRYG+sEMCinZEn9 rjfXjPDQZr3jliFeZPYcDivFyFe8Q9higwCPu0R42hj03nxz4ZKkkT+i5MoEt2ZV mt61t2lbvSETYDdF/sq/bojEMTL62Yhr+fwoXvz2xDPkOx59tfcAi3ewk= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=miVmFUFAHhevkzhJZlJWGt1R/ak=; b=pn6ew8v4FtMVrX/fXuAh 9Q5/Am0kU9SUS+4do40ujsl0ojqDSzKr1Pb9z7rWSKQZfCUr2URQZwafM41fUBTF 91nyuaIgQT67X1cYLDMLBol9l2l0K7j4DKtOrzmG2/cSeK5dcENpXZLnVOZfNJve vfzu4zfpqKt/XcSPQkhcSEk= Received: (qmail 109135 invoked by alias); 10 Apr 2018 15:06:20 -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 108334 invoked by uid 89); 10 Apr 2018 15:06:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Union, H*r:200, invasive, 6825 X-HELO: mail-yw0-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Apr 2018 15:06:12 +0000 Received: by mail-yw0-f173.google.com with SMTP id v68so4105307ywg.13 for ; Tue, 10 Apr 2018 08:06:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=sZ8jgpPpCJO3ip9ThOjnVc+VGNdaIePhVXWCsQyqrjc=; b=QoEosJhmyLvvaT15YxPm43FRUYAyV1d7kZZZ+IDm4taeDq4VFrbYBJ4jPfvHK2DkYm p5pslspIMAd1BDh9xfBn1xkrfOSxDRSyuLea0mYjH/uFVKIl0NhJti04j06RSFktjjeH Aywwcku06RswiEcaij0EvHvfDqaVta7UbrsdTZBuMcZVPfusfVryWc5FQIn7YMyJFXZh 8z64rrQejmuXzadaNY3XFBR6KuKpxRCR3MIIqKBaNPhNQvciGQwJLETJA3alzaUApm0/ FHR0x/gzV06SzEaiNxt47IP/Zxac+QD446i5/l7zQRiPITglj+bgRuRJmcttDzvawEJH 3q3Q== X-Gm-Message-State: ALQs6tCR6Zo9ZlFcW8KL7tlDVPsfrpBvN3eYmhjlx66nAwiJgAfjizAd 6q+EUmo5KDRq1j3ydPM0s+U= X-Google-Smtp-Source: AIpwx4/THBBTKjOLbmXvBEdqZscfLWYLpBsoOxGfBUMZeKBvRemxyYKG7P2Vrx1XvFbJrbppN3WeGg== X-Received: by 10.13.213.138 with SMTP id x132mr504984ywd.3.1523372770175; Tue, 10 Apr 2018 08:06:10 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:aaf7]) by smtp.googlemail.com with ESMTPSA id o198sm1057951ywo.25.2018.04.10.08.06.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 08:06:09 -0700 (PDT) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] empty-declarations Message-ID: <2d7e797e-7fb8-5ec0-b3b4-026d306817f8@acm.org> Date: Tue, 10 Apr 2018 11:06:07 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Jason, thanks for looking up about empty-decls. This patch implements the C++11 change. At namespace-scope & class-scope we're now silent about empty declarations, when not in C++-98 mode. The class-scope change was a little more invasive, because we silently accepted a semicolon after an in-class function definition: class X { void foo () {}; // semi-colon accepted }; And we emitted a fixit for that case. This isn't a regression. I don't think anyone's complained. Jason, WDYT about committing this now? nathan 2018-04-10 Nathan Sidwell * parser.c (cp_parser_declaration_seq_opt): Permit empty-declaration in c++11. (cp_parser_member_declaration): Likewise. * g++.dg/semicolon-fixits.C: Delete. * g++.dg/cpp0x/semicolon.C: New. * g++.dg/warn/Wextra-semi.C: C++98 only. * g++.dg/warn/pedantic2.C: C++98 only. * g++.old-deja/g++.bugs/900404_04.C: C++98 only. * g++.old-deja/g++.jason/parse11.C: C++98 only. * g++.old-deja/g++.law/missed-error2.C: C++98 only. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 259268) +++ cp/parser.c (working copy) @@ -12614,9 +12614,9 @@ cp_parser_declaration_seq_opt (cp_parser if (token->type == CPP_SEMICOLON) { /* A declaration consisting of a single semicolon is - invalid. Allow it unless we're being pedantic. */ + valid since C++11. */ cp_lexer_consume_token (parser->lexer); - if (!in_system_header_at (input_location)) + if (cxx_dialect < cxx11 && !in_system_header_at (input_location)) pedwarn (input_location, OPT_Wpedantic, "extra %<;%>"); continue; } @@ -23445,6 +23445,7 @@ cp_parser_member_specification_opt (cp_p C++0x Extensions: member-declaration: + empty-declaration static_assert-declaration */ static void @@ -23472,6 +23473,15 @@ cp_parser_member_declaration (cp_parser* return; } + if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) + { + /* C++11 allow an empty-declaration. */ + cp_lexer_consume_token (parser->lexer); + if (cxx_dialect < cxx11 && !in_system_header_at (input_location)) + pedwarn (input_location, OPT_Wpedantic, "extra %<;%>"); + return; + } + /* Check for a template-declaration. */ if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE)) { @@ -23912,8 +23922,9 @@ cp_parser_member_declaration (cp_parser* finish_member_declaration (decl); /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); - /* If the next token is a semicolon, consume it. */ - if (token->type == CPP_SEMICOLON) + /* If the next token is a semicolon, consume it in + c++98. c++11 made this always ok. */ + if (cxx_dialect < cxx11 && token->type == CPP_SEMICOLON) { location_t semicolon_loc = cp_lexer_consume_token (parser->lexer)->location; Index: testsuite/g++.dg/cpp0x/semicolon.C =================================================================== --- testsuite/g++.dg/cpp0x/semicolon.C (revision 0) +++ testsuite/g++.dg/cpp0x/semicolon.C (working copy) @@ -0,0 +1,10 @@ +// { dg-do compile { target c++11 } } +// C++11 allows empty decls + +; // OK + + +struct X +{ + ; // OK +}; Index: testsuite/g++.dg/semicolon-fixits.C =================================================================== --- testsuite/g++.dg/semicolon-fixits.C (revision 259268) +++ testsuite/g++.dg/semicolon-fixits.C (working copy) @@ -1,17 +0,0 @@ -/* { dg-options "-fdiagnostics-show-caret -Wpedantic" } */ - -/* Struct with extra semicolon. */ -struct s1 { int i;; }; /* { dg-warning "19: extra .;." } */ -/* { dg-begin-multiline-output "" } - struct s1 { int i;; }; - ^ - - - { dg-end-multiline-output "" } */ - -/* Union with extra semicolon. */ -union u1 { int i;; }; /* { dg-warning "18: extra .;." } */ -/* { dg-begin-multiline-output "" } - union u1 { int i;; }; - ^ - - - { dg-end-multiline-output "" } */ Index: testsuite/g++.dg/warn/Wextra-semi.C =================================================================== --- testsuite/g++.dg/warn/Wextra-semi.C (revision 259268) +++ testsuite/g++.dg/warn/Wextra-semi.C (working copy) @@ -1,3 +1,5 @@ +// { dg-do compile { target c++98_only } } + // { dg-options "-Wextra-semi -fdiagnostics-show-caret" } struct A Index: testsuite/g++.dg/warn/pedantic2.C =================================================================== --- testsuite/g++.dg/warn/pedantic2.C (revision 259268) +++ testsuite/g++.dg/warn/pedantic2.C (working copy) @@ -1,3 +1,4 @@ +// { dg-do compile { target c++98_only } } // { dg-options "-pedantic" } class foo Index: testsuite/g++.old-deja/g++.bugs/900404_04.C =================================================================== --- testsuite/g++.old-deja/g++.bugs/900404_04.C (revision 259268) +++ testsuite/g++.old-deja/g++.bugs/900404_04.C (working copy) @@ -1,4 +1,4 @@ -// { dg-do assemble } +// { dg-do assemble { target c++98_only } } // g++ 1.37.1 bug 900404_04 // [dcl.dcl] explains that simple-declarations may omit the @@ -13,6 +13,7 @@ int i; +// Ok in C++11 up ; // { dg-error "extra ';'" } int main () { return 0; } Index: testsuite/g++.old-deja/g++.jason/parse11.C =================================================================== --- testsuite/g++.old-deja/g++.jason/parse11.C (revision 259268) +++ testsuite/g++.old-deja/g++.jason/parse11.C (working copy) @@ -1,4 +1,4 @@ -// { dg-do assemble } +// { dg-do assemble { target c++98_only } } // PRMS Id: 6825 class aClass Index: testsuite/g++.old-deja/g++.law/missed-error2.C =================================================================== --- testsuite/g++.old-deja/g++.law/missed-error2.C (revision 259268) +++ testsuite/g++.old-deja/g++.law/missed-error2.C (working copy) @@ -1,10 +1,11 @@ -// { dg-do assemble } +// { dg-do assemble { target c++98_only } } // GROUPS passed missed-error // missed-error file // From: ndc!don@csvax.cs.caltech.edu (Don Erway) // Date: Thu, 21 May 92 15:40:45 PDT // Subject: More on [g++ 2.1 : overloaded function selection incorrect] // Message-ID: <9205212240.AA17934@ndc.com> +// naked semi-colons ok in C++11 #include