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

            Bug ID: 71469
           Summary: Print possible override candidates when a method is
                    marked override but doesn't override
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b7.10110111 at gmail dot com
  Target Milestone: ---

Currently for this code

struct Base
{
    virtual int funct(int);
};
struct Der
{
    int func(int) override;
    int funct() override;
};
int main(){}

g++ gives the following error:

test.cpp:7:9: error: ‘int Der::func(int)’ marked ‘override’, but does not
override
     int func(int) override;
         ^
test.cpp:8:9: error: ‘int Der::funct()’ marked ‘override’, but does not
override
     int funct() override;
         ^

Now one has to look into the declaration of Base to find out what's actually
wrong.

It'd be nice if g++ suggested possible candidates:

1. For the first case in the above example, int func(int), do something similar
to "no such member" error (i.e. suggest function name correction) if the
supposed override matches in parameter types;
2. For the second case, int funct(), just list the name(s) of virtual functions
in the base class matching the name of the supposed override.

This will make it much simpler to immediately see some trivial errors like e.g.
omitting a parameter or using int instead of long.

Reply via email to