This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/82334] New: improve list of candidates for a member definition that doesn't match declaration


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

            Bug ID: 82334
           Summary: improve list of candidates for a member definition
                    that doesn't match declaration
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

When the prototype of a member function definition doesn't match its
declaration GCC prints an error followed by a list of candidate overloads of
the member function.  That helpful but not as much as it could be.  It would be
even more useful if the note for each candidate indicated the way in which it
differs from the prototype of the definition, e.g., by underlining a missing
qualifier.

The test case below shows how the current note is less than optimal:

$ cat a.C && gcc -O2 -S -Wall -Wextra a.C
struct S {
  typedef int descriptor_t;
  typedef double real_t;
  typedef const char *strptr_t;
  typedef void *handle_t;

  int f (int, double, const char*, void*) const;
};

int S::f (descriptor_t, real_t, strptr_t, handle_t)
{
  return 0;
}
a.C:10:5: error: no declaration matches ‘int S::f(S::descriptor_t, S::real_t,
S::strptr_t, S::handle_t)’
 int S::f (descriptor_t, real_t, strptr_t, handle_t)
     ^
a.C:7:7: note: candidate is: ‘int S::f(int, double, const char*, void*) const’
   int f (int, double, const char*, void*) const;
       ^
a.C:1:8: note: ‘struct S’ defined here
 struct S {
        ^


In contrast, Clang emits a more helpful note:

.C:10:8: error: out-of-line definition of 'f' does not match any declaration in
      'S'
int S::f (descriptor_t, real_t, strptr_t, handle_t)
       ^
t.C:7:7: note: member declaration does not match because it is const qualified
  int f (int, double, const char*, void*) const;
      ^                                   ~~~~~
1 error generated.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]