public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96077] New: GCC accepts ill-legal local enum definition
@ 2020-07-06 12:31 haoxintu at gmail dot com
  2020-07-06 13:44 ` [Bug c++/96077] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-06 12:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96077
           Summary: GCC accepts ill-legal local enum definition
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi, all.

This code, test.cc, has a grammar issue in "missing ')'", but GCC accepts it
well.

$cat test.cc
enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 } g_e; //reject
int main () {
    enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 /* missing ")" here */ } l_e; //accept
    return 0;
}

$g++ test.cc
test.cc:1:35: error: expected ‘)’ before ‘}’ token
    1 | enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 } g_e; //reject
      |                            ~      ^~
      |                                  )

GCC only rejects line 1 but accepts line 3.

While in Clang

$clang++ test.cc
test.cc:1:36: error: expected ')'
enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 } g_e; //reject
                                   ^
test.cc:1:28: note: to match this '('
enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 } g_e; //reject
                           ^
test.cc:3:63: error: expected ')'
    enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 /* missing ")" here */ } l_e; //accept
                                                              ^
test.cc:3:32: note: to match this '('
    enum { a = ( 1 ) ? ( 2 ) : ( 2 + 1 /* missing ")" here */ } l_e; //accept
                               ^
2 errors generated.


$g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/haoxin/corpus-compilers/gcc-trunk/gcc-master/build/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure
--prefix=/home/haoxin/corpus-compilers/gcc-trunk/gcc-master/build/
--enable-languages=c,c++ CC=gcc CXX=g++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20200630 (experimental) (GCC)

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

end of thread, other threads:[~2020-07-13 15:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 12:31 [Bug c++/96077] New: GCC accepts ill-legal local enum definition haoxintu at gmail dot com
2020-07-06 13:44 ` [Bug c++/96077] " redi at gcc dot gnu.org
2020-07-06 13:50 ` haoxintu at gmail dot com
2020-07-08 20:22 ` mpolacek at gcc dot gnu.org
2020-07-09 20:35 ` mpolacek at gcc dot gnu.org
2020-07-09 21:40 ` mpolacek at gcc dot gnu.org
2020-07-10 15:48 ` mpolacek at gcc dot gnu.org
2020-07-13 15:16 ` cvs-commit at gcc dot gnu.org
2020-07-13 15:19 ` cvs-commit at gcc dot gnu.org
2020-07-13 15:19 ` mpolacek at gcc dot gnu.org
2020-07-13 15:19 ` mpolacek 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).