[Bug c++/85004] New: ambiguous diagnostic: passing ‘const S’ as ‘this’ argument discards qualifiers

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 20 17:58:00 GMT 2018


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

            Bug ID: 85004
           Summary: ambiguous diagnostic: passing ‘const S’ as ‘this’
                    argument discards qualifiers
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

When invoking a non-const member function from a const one, GCC issues an error
message like those below.  The error message is ambiguous: it doesn't make is
clear which this it refers to.  In the first case, underling the first "this"
would help.  In the second case rephrasing the error to say something like
"passing ‘const S’ as the implicit ‘this’ argument discards qualifiers" would
help avoid the confusion.

$ cat u.C && gcc -S -Wall u.C
struct S {
  void f (const S*);

  void g () const
  {
    this->f (this);   // which 'this?'

    f (this);         // ditto
  }
};
u.C: In member function ‘void S::g() const’:
u.C:6:18: error: passing ‘const S’ as ‘this’ argument discards qualifiers
[-fpermissive]
     this->f (this);   // which 'this?'
                  ^
u.C:2:8: note:   in call to ‘void S::f(const S*)’
   void f (const S*);
        ^
u.C:8:12: error: passing ‘const S’ as ‘this’ argument discards qualifiers
[-fpermissive]
     f (this);         // ditto
            ^
u.C:2:8: note:   in call to ‘void S::f(const S*)’
   void f (const S*);
        ^


More information about the Gcc-bugs mailing list