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

            Bug ID: 101526
           Summary: Improve diagnostic for trailing comma in base-clause
                    in class-head
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

struct A { };
struct B : A, { };


GCC correctly says:

base.C:2:15: error: expected class-name before ‘{’ token
    2 | struct B : A, { };
      |               ^

It would be nice if we offered a fix-it hint to remove the trailing comma.

This can easily happen when refactoring code if you remove the last base-class
from a list of several. When each base is on its own line, the location printed
is not helpful:

struct Base_class_one { };
struct Base_class_two_with_long_name { };
struct Claaaaaas
: Base_class_one,
  Base_class_two_with_long_name,
  // Removed_base_class
{
};


base.C:7:1: error: expected class-name before ‘{’ token
    7 | {
      | ^

This would be much better if it pointed to the trailing comma, and suggested
removing it.

See also PR 101519 which requests another improvement to the same diagnostic,
but with a different cause.

Reply via email to