public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94571] New: Error: Expected comma or semicolon, comma found
@ 2020-04-12 23:37 bisqwit at iki dot fi
  2020-04-12 23:43 ` [Bug c++/94571] " bisqwit at iki dot fi
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bisqwit at iki dot fi @ 2020-04-12 23:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94571
           Summary: Error: Expected comma or semicolon, comma found
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bisqwit at iki dot fi
  Target Milestone: ---

void foo()
{
    int test1[2], test2[2];
    auto [a,b] = test1, [c,d] = test2;
}

The error message given for this (invalid) C++17 code is a bit confusing.

tmp.cc: In function ‘void foo()’:
tmp.cc:4:23: error: expected ‘,’ or ‘;’ before ‘,’ token
    4 |     auto [a,b] = test1, [c,d] = test2;

You expected comma, found comma. So what is the problem? The proper error
message would be to only expect a semicolon.

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
@ 2020-04-12 23:43 ` bisqwit at iki dot fi
  2020-04-13 17:14 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bisqwit at iki dot fi @ 2020-04-12 23:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Joel Yliluoma <bisqwit at iki dot fi> ---
      |                       ^

(Missing line from the paste)

The problem exists since GCC 7. (GCC 6 and earlier did not support structured
bindings.)

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
  2020-04-12 23:43 ` [Bug c++/94571] " bisqwit at iki dot fi
@ 2020-04-13 17:14 ` mpolacek at gcc dot gnu.org
  2020-04-14  8:30 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-13 17:14 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2020-04-13
           Keywords|                            |diagnostic

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.

clang++ says
error: decomposition declaration must be the only declaration in its group
which is much better.

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
  2020-04-12 23:43 ` [Bug c++/94571] " bisqwit at iki dot fi
  2020-04-13 17:14 ` mpolacek at gcc dot gnu.org
@ 2020-04-14  8:30 ` jakub at gcc dot gnu.org
  2020-04-14 14:27 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-14  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is a pasto, either we can go with the simple:
2020-04-14  Jakub Jelinek  <jakub@redhat.com>

        PR c++/94571
        * parser.c (cp_parser_simple_declaration): Fix up a pasto in
        diagnostics.

        * g++.dg/cpp1z/decomp51.C: New test.

--- gcc/cp/parser.c.jj  2020-04-08 11:59:23.772460767 +0200
+++ gcc/cp/parser.c     2020-04-14 10:15:54.824034781 +0200
@@ -13675,7 +13675,7 @@ cp_parser_simple_declaration (cp_parser*
            if ((decl != error_mark_node
                 && DECL_INITIAL (decl) != error_mark_node)
                || cp_parser_uncommitted_to_tentative_parse_p (parser))
-             cp_parser_error (parser, "expected %<,%> or %<;%>");
+             cp_parser_error (parser, "expected %<;%>");
            /* Skip tokens until we reach the end of the statement.  */
            cp_parser_skip_to_end_of_statement (parser);
            /* If the next token is now a `;', consume it.  */
--- gcc/testsuite/g++.dg/cpp1z/decomp51.C.jj    2020-04-14 10:18:58.318313777
+0200
+++ gcc/testsuite/g++.dg/cpp1z/decomp51.C       2020-04-14 10:19:31.347823985
+0200
@@ -0,0 +1,16 @@
+// PR c++/94571
+// { dg-do compile { target c++17 } }
+
+void
+foo ()
+{
+  int e[2], f[2];
+  auto [a,b] = e, [c,d] = f;   // { dg-error "expected ';' before ',' token" }
+}
+
+void
+bar ()
+{
+  int e[2];
+  auto [a, b] = e );           // { dg-error "expected ';' before '\\\)'
token" }
+}

change or can have a separate diagnostics for when there is a comma (but still
want the diagnostic about only ; expected when there is random garbage after
the expression).

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
                   ` (2 preceding siblings ...)
  2020-04-14  8:30 ` jakub at gcc dot gnu.org
@ 2020-04-14 14:27 ` mpolacek at gcc dot gnu.org
  2020-04-14 19:10 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-04-14 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think that won't handle

  auto x(1), [e,f] = test2;

where we should also say what clang says (or at least give inform()).

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
                   ` (3 preceding siblings ...)
  2020-04-14 14:27 ` mpolacek at gcc dot gnu.org
@ 2020-04-14 19:10 ` jakub at gcc dot gnu.org
  2020-04-16  5:20 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-04-14 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #4)
> I think that won't handle
> 
>   auto x(1), [e,f] = test2;
> 
> where we should also say what clang says (or at least give inform()).

That gives
error: expected unqualified-id before ‘[’ token
right now.  It would be quite a different spot that would need to handle that,
and the question is if we should do it whenever seeing just [ or if we should
in that case e.g. try to parse tentatively the structured binding or at least
part of it and only give that diagnostics if it looks like an otherwise valid
structured binding.

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
                   ` (4 preceding siblings ...)
  2020-04-14 19:10 ` jakub at gcc dot gnu.org
@ 2020-04-16  5:20 ` cvs-commit at gcc dot gnu.org
  2020-09-16 19:20 ` cvs-commit at gcc dot gnu.org
  2020-09-17 17:33 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-16  5:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:e4658c7dbbe88f742c96e5f58ee4a6d549d642ca

commit r10-7745-ge4658c7dbbe88f742c96e5f58ee4a6d549d642ca
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 16 07:19:57 2020 +0200

    c++: Fix pasto in structured binding diagnostics [PR94571]

    This snippet has been copied from the non-structured binding declaration
    parsing later in the function, and while for non-structured bindings
    it can be followed by comma or semicolon, structured bindings may be
    only followed by semicolon.

    Or, do we want to have a different message for the case when there is
    a comma (and keep this corrected one only if there is something else)
    that would explain better what is the bug (or add a fix-it hint)?
    Marek said in the PR that clang++ reports
    error: decomposition declaration must be the only declaration in its group

    There is another thing Marek noted (though, something for different spot),
    that diagnostic for auto x(1), [e,f] = test2; could also use a clearer
    wording like the above (or a fix-it hint), but the question is if we should
    assume [ after , as a structured binding or if we should do some tentative
    parsing first to figure out if it looks like a structured binding.

    2020-04-16  Jakub Jelinek  <jakub@redhat.com>

            PR c++/94571
            * parser.c (cp_parser_simple_declaration): Fix up a pasto in
            diagnostics.

            * g++.dg/cpp1z/decomp51.C: New test.

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
                   ` (5 preceding siblings ...)
  2020-04-16  5:20 ` cvs-commit at gcc dot gnu.org
@ 2020-09-16 19:20 ` cvs-commit at gcc dot gnu.org
  2020-09-17 17:33 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-16 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:a43981bb51fd0b8e68452faea6ec160cbea058e5

commit r9-8879-ga43981bb51fd0b8e68452faea6ec160cbea058e5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 16 07:19:57 2020 +0200

    c++: Fix pasto in structured binding diagnostics [PR94571]

    This snippet has been copied from the non-structured binding declaration
    parsing later in the function, and while for non-structured bindings
    it can be followed by comma or semicolon, structured bindings may be
    only followed by semicolon.

    Or, do we want to have a different message for the case when there is
    a comma (and keep this corrected one only if there is something else)
    that would explain better what is the bug (or add a fix-it hint)?
    Marek said in the PR that clang++ reports
    error: decomposition declaration must be the only declaration in its group

    There is another thing Marek noted (though, something for different spot),
    that diagnostic for auto x(1), [e,f] = test2; could also use a clearer
    wording like the above (or a fix-it hint), but the question is if we should
    assume [ after , as a structured binding or if we should do some tentative
    parsing first to figure out if it looks like a structured binding.

    2020-04-16  Jakub Jelinek  <jakub@redhat.com>

            PR c++/94571
            * parser.c (cp_parser_simple_declaration): Fix up a pasto in
            diagnostics.

            * g++.dg/cpp1z/decomp51.C: New test.

    (cherry picked from commit e4658c7dbbe88f742c96e5f58ee4a6d549d642ca)

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

* [Bug c++/94571] Error: Expected comma or semicolon, comma found
  2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
                   ` (6 preceding siblings ...)
  2020-09-16 19:20 ` cvs-commit at gcc dot gnu.org
@ 2020-09-17 17:33 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-17 17:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 8.5 in r8-10487-g189c10499d796877e22c7f019a2805099fab8509 and by the
above commit for 9.4+ too.

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

end of thread, other threads:[~2020-09-17 17:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-12 23:37 [Bug c++/94571] New: Error: Expected comma or semicolon, comma found bisqwit at iki dot fi
2020-04-12 23:43 ` [Bug c++/94571] " bisqwit at iki dot fi
2020-04-13 17:14 ` mpolacek at gcc dot gnu.org
2020-04-14  8:30 ` jakub at gcc dot gnu.org
2020-04-14 14:27 ` mpolacek at gcc dot gnu.org
2020-04-14 19:10 ` jakub at gcc dot gnu.org
2020-04-16  5:20 ` cvs-commit at gcc dot gnu.org
2020-09-16 19:20 ` cvs-commit at gcc dot gnu.org
2020-09-17 17:33 ` 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).