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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Current trunk gives:

cv.cc: In member function ‘void Foo::bar2(const Foo&)’:
cv.cc:4:26: error: passing ‘const Foo’ as ‘this’ argument discards qualifiers
[-fpermissive]
                 foo.bar1();
                          ^
cv.cc:2:14: note:   in call to ‘void Foo::bar1()’
         void bar1() {}
              ^~~~


With this patch:

--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7799,7 +7799,24 @@ build_over_call (struct z_candidate *cand, int flags,
tsubst_flags_t complain)
              if (permerror (input_location, "passing %qT as %<this%> "
                             "argument discards qualifiers",
                             TREE_TYPE (argtype)))
-               inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD", fn);
+               {
+                 int argquals = cp_type_quals (TREE_TYPE (argtype));
+                 int fnquals = cp_type_quals (TREE_TYPE (fn));
+                 int discarded = argquals & ~fnquals;
+                 bool non_const = discarded & TYPE_QUAL_CONST;
+                 bool non_volatile = discarded & TYPE_QUAL_VOLATILE;
+                 const char *descr;
+                 if (non_const && non_volatile)
+                   descr = " which is non-const and non-volatile";
+                 else if (non_const)
+                   descr = " which is non-const";
+                 else if (non_volatile)
+                   descr = " which is non-volatile";
+                 else
+                   descr = "";
+                 inform (DECL_SOURCE_LOCATION (fn), "  in call to %qD%s",
+                         fn, descr);
+               }
            }
          else
            return error_mark_node;


we get:

cv.cc: In member function ‘void Foo::bar2(const Foo&)’:
cv.cc:4:26: error: passing ‘const Foo’ as ‘this’ argument discards qualifiers
[-fpermissive]
                 foo.bar1();
                          ^
cv.cc:2:14: note:   in call to ‘void Foo::bar1()’ which is non-const
         void bar1() {}
              ^~~~

Note the addition of "which is non-const" to the note.

Reply via email to