public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11?
@ 2020-07-05 15:33 haoxintu at gmail dot com
  2020-07-06 10:48 ` [Bug c++/96068] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-05 15:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

            Bug ID: 96068
           Summary: Extra semicolon outside of a function should be
                    allowed after c++11?
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi, all.

As the summary, extra ";" should be allowed in GCC after -std=c++11 and
shouldn't give a diagnostic message about it? I know this is forbidden in
c++98.

For example,

$cat test.cc
void foo() { };

$g++ -c -std=c++98 -pedantic-errors test.cc
test.cc:1:16: error: extra ';' [-Wpedantic]
    1 | void foo () { };
      |                ^

$g++ -c -std=c++11 -pedantic-errors test.cc
test.cc:1:16: error: extra ';' [-Wpedantic]
    1 | void foo () { };
      |                ^

While in Clang, this is accepted in c++11 or later.

$clang++ -c -std=c++98 -pedantic-errors test.cc
test.cc:1:15: error: extra ';' outside of a function is a C++11 extension
[-Werror,-Wc++11-extra-semi]
void foo() { };
              ^
1 error generated.

There is also a related bug report in llvm: 

https://bugs.llvm.org/show_bug.cgi?id=46288

They suggested that "If GCC rejects this under -pedantic-errors in C++11 or
later, I think that's a GCC bug."

I try to find a similar bug report in GCC but failed. 

Did I miss something? Thank you very much.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
@ 2020-07-06 10:48 ` redi at gcc dot gnu.org
  2020-07-06 15:02 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-06 10:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-07-06
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|diagnostic                  |

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13502,10 +13502,11 @@ cp_parser_toplevel_declaration (cp_parser* parser)
     cp_parser_pragma (parser, pragma_external, NULL);
   else if (token->type == CPP_SEMICOLON)
     {
-      /* A declaration consisting of a single semicolon is
-        invalid.  Allow it unless we're being pedantic.  */
       cp_lexer_consume_token (parser->lexer);
-      pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
+      /* A declaration consisting of a single semicolon is invalid
+       * before C++11.  Allow it unless we're being pedantic.  */
+      if (cxx_dialect < cxx11)
+       pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
     }
   else
     /* Parse the declaration itself.  */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
  2020-07-06 10:48 ` [Bug c++/96068] " redi at gcc dot gnu.org
@ 2020-07-06 15:02 ` redi at gcc dot gnu.org
  2020-07-06 16:12 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-06 15:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Keywords|                            |patch
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch submitted:
https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549453.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
  2020-07-06 10:48 ` [Bug c++/96068] " redi at gcc dot gnu.org
  2020-07-06 15:02 ` redi at gcc dot gnu.org
@ 2020-07-06 16:12 ` cvs-commit at gcc dot gnu.org
  2020-07-06 16:13 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-06 16:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:92414bb6b077642eefc24080637b6bc766499391

commit r11-1852-g92414bb6b077642eefc24080637b6bc766499391
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jul 6 15:58:33 2020 +0100

    c++: Allow empty-declaration in C++11 and later (PR 96068)

    Since C++11 a semim-colon on its own at namespace scope is not invalid,
    so do not give a pedantic diagnostic about it.

    gcc/cp/ChangeLog:

            PR c++/96068
            * parser.c (cp_parser_toplevel_declaration): Only do pedwarn for
            empty-declaration in C++98.

    gcc/testsuite/ChangeLog:

            * g++.old-deja/g++.bugs/900404_04.C: Add c++98_only selector to
            dg-error for extra ';'.
            * g++.old-deja/g++.law/missed-error2.C: Likewise.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
                   ` (2 preceding siblings ...)
  2020-07-06 16:12 ` cvs-commit at gcc dot gnu.org
@ 2020-07-06 16:13 ` redi at gcc dot gnu.org
  2021-11-08 10:31 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-06 16:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |11.0
         Resolution|---                         |FIXED

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
                   ` (3 preceding siblings ...)
  2020-07-06 16:13 ` redi at gcc dot gnu.org
@ 2021-11-08 10:31 ` pinskia at gcc dot gnu.org
  2021-12-07  5:13 ` pinskia at gcc dot gnu.org
  2022-05-09 16:19 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-08 10:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mail at milianw dot de

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 103131 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
                   ` (4 preceding siblings ...)
  2021-11-08 10:31 ` pinskia at gcc dot gnu.org
@ 2021-12-07  5:13 ` pinskia at gcc dot gnu.org
  2022-05-09 16:19 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-07  5:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anders.granlund.0 at gmail dot com

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 67013 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/96068] Extra semicolon outside of a function should be allowed after c++11?
  2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
                   ` (5 preceding siblings ...)
  2021-12-07  5:13 ` pinskia at gcc dot gnu.org
@ 2022-05-09 16:19 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-09 16:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96068

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I wonder if we shouldn't have a style warning for this though, if the empty
statement's ; is immediately after } in the source, tell user it is
unnecessary,
while not warning if there is some comment or newline or whitespace etc. in
between.
Ran into this while backporting PR105256 to gcc-10 branch which doesn't have
this fix and the testcase contains such a useless semicolon:
void S::Prefs::Load() {
  *this = {};
};

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-09 16:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 15:33 [Bug c++/96068] New: Extra semicolon outside of a function should be allowed after c++11? haoxintu at gmail dot com
2020-07-06 10:48 ` [Bug c++/96068] " redi at gcc dot gnu.org
2020-07-06 15:02 ` redi at gcc dot gnu.org
2020-07-06 16:12 ` cvs-commit at gcc dot gnu.org
2020-07-06 16:13 ` redi at gcc dot gnu.org
2021-11-08 10:31 ` pinskia at gcc dot gnu.org
2021-12-07  5:13 ` pinskia at gcc dot gnu.org
2022-05-09 16:19 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).