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

            Bug ID: 107268
           Summary: Poor diagnostic for missing colon in ctor-initializer
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

struct UsesAlloc
{
  bool passed_alloc;

  UsesAlloc(int) passed_alloc(false) { }
};

The user forgot to type the ':' in the constructor, but GCC says:

parser_diag.C:5:16: error: expected ‘;’ at end of member declaration
    5 |   UsesAlloc(int) passed_alloc(false) { }
      |                ^
      |                 ;
parser_diag.C:5:31: error: expected identifier before ‘false’
    5 |   UsesAlloc(int) passed_alloc(false) { }
      |                               ^~~~~
parser_diag.C:5:31: error: expected ‘,’ or ‘...’ before ‘false’
parser_diag.C:5:18: error: ISO C++ forbids declaration of ‘passed_alloc’ with
no type [-fpermissive]
    5 |   UsesAlloc(int) passed_alloc(false) { }
      |                  ^~~~~~~~~~~~
parser_diag.C:5:40: error: ‘int UsesAlloc::passed_alloc(int)’ conflicts with a
previous declaration
    5 |   UsesAlloc(int) passed_alloc(false) { }
      |                                        ^
parser_diag.C:3:8: note: previous declaration ‘bool UsesAlloc::passed_alloc’
    3 |   bool passed_alloc;
      |        ^~~~~~~~~~~~
parser_diag.C: In member function ‘int UsesAlloc::passed_alloc(int)’:
parser_diag.C:5:40: warning: no return statement in function returning non-void
[-Wreturn-type]
    5 |   UsesAlloc(int) passed_alloc(false) { }
      |                                        ^


That's a lot of output. Clang is less noisy, though still not very helpful:

parser_diag.C:5:17: error: expected ';' at end of declaration list
  UsesAlloc(int) passed_alloc(false) { }
                ^
                ;
1 error generated.

EDG is similar:

"parser_diag.C", line 5: error: expected a ";"
    UsesAlloc(int) passed_alloc(false) { }
                   ^

1 error detected in the compilation of "parser_diag.C".


It would be better GCC if print a single line like Clang and EDG, but it would
be even better if it suggested that a ':' is missing, instead of a ';' (because
either of those is valid there).

Reply via email to