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

            Bug ID: 101232
           Summary: Bad error message with stray semicolon in initializer
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tobi at gcc dot gnu.org
  Target Milestone: ---

This example (Link to compiler explorer: -> https://godbolt.org/z/rxsreYs8Y
<-):

=========================

struct X {
    int a;
    int b;
};

void f() {
    auto x = X{ 1, 2; };
}
========================

Gives the fairly misleading error message

<source>: In function 'void f()':
<source>:7:15: error: expected primary-expression before '{' token
    7 |     auto x = X{ 1, 2; };
      |               ^

The error message is of the same kind all the way from GCC 4.1.2 up to the
current trunk.

For comparison, clang gives the much more helpful
<source>:7:21: error: unexpected ';' before '}'
    auto x = X{ 1, 2; };
                    ^

Reply via email to