[Bug c++/105840] New: confusing diagnostic when naming the wrong class in a constructor

barry.revzin at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jun 3 17:54:45 GMT 2022


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

            Bug ID: 105840
           Summary: confusing diagnostic when naming the wrong class in a
                    constructor
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

In this code:

template <typename T> struct X { };

struct A {
    A(int i);
    A(X<int> x);
};

struct B {
    A(int i);
    A(X<int> x);
};

I was copying the constructors from A into B, and forgot to change the name.
This is, indeed, ill-formed.

However, this is what gcc tells me:

<source>:9:7: error: expected unqualified-id before 'int'
    9 |     A(int i);
      |       ^~~
<source>:9:7: error: expected ')' before 'int'
    9 |     A(int i);
      |      ~^~~
      |       )
<source>:10:14: error: invalid declarator before 'x'
   10 |     A(X<int> x);
      |              ^
<source>:10:13: error: expected ')' before 'x'
   10 |     A(X<int> x);
      |      ~      ^~
      |             )

Clang does at least point me to the A, but otherwise provides a
differently-confusing diagnostic about the parentheses?

<source>:9:7: error: expected member name or ';' after declaration specifiers
    A(int i);
    ~ ^
<source>:9:7: error: expected ')'
<source>:9:6: note: to match this '('
    A(int i);
     ^
<source>:10:14: error: expected ')'
    A(X<int> x);
             ^
<source>:10:6: note: to match this '('
    A(X<int> x);
     ^
<source>:10:7: error: member 'X' cannot have template arguments
    A(X<int> x);
      ^~~~~~


More information about the Gcc-bugs mailing list