re PR c++/10496 ([diagnostic] erroneus suggestion in diagnostic asks the user to...
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Mon, 5 May 2003 14:35:58 +0000 (14:35 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Mon, 5 May 2003 14:35:58 +0000 (14:35 +0000)
PR c++/10496
* typeck.c (build_unary_op): Don't output const qualifier when
output invalid pointer-to-member diagnostics.

* g++.dg/warn/pmf1.C: New test.

From-SVN: r66481

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pmf1.C [new file with mode: 0644]

index f557fe297a89f6ba45fa2dd9e3e7bb7a4b76d934..3567da7c0b2f59758efc969eb1b1c59c2223f0ed 100644 (file)
@@ -1,3 +1,9 @@
+2003-05-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/10496
+       * typeck.c (build_unary_op): Don't output const qualifier when
+       output invalid pointer-to-member diagnostics.
+
 2003-05-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        * decl.c: Fix typos.
index bb99adc6fc02dccd5e05ba95fd41d616949bb845..35073dc3a7cfeb6aecb931232169d0376d1e98a1 100644 (file)
@@ -4435,12 +4435,21 @@ build_unary_op (code, xarg, noconvert)
 
          if (! flag_ms_extensions)
            {
+             /* Inside constant member functions, the `this' pointer
+                contains an extra const qualifier.  TYPE_MAIN_VARIANT
+                is used here to remove this const from the diagnostics.  */
              if (current_class_type
                  && TREE_OPERAND (arg, 0) == current_class_ref)
                /* An expression like &memfn.  */
-               pedwarn ("ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say `&%T::%D'", base, name);
+               pedwarn ("ISO C++ forbids taking the address of an unqualified"
+                        " or parenthesized non-static member function to form"
+                        " a pointer to member function.  Say `&%T::%D'",
+                        TYPE_MAIN_VARIANT (base), name);
              else
-               pedwarn ("ISO C++ forbids taking the address of a bound member function to form a pointer to member function.  Say `&%T::%D'", base, name);
+               pedwarn ("ISO C++ forbids taking the address of a bound member"
+                        " function to form a pointer to member function."
+                        "  Say `&%T::%D'",
+                        TYPE_MAIN_VARIANT (base), name);
            }
          arg = build_offset_ref (base, name);
         }
index aec72724b3ee46e02efdf3d161276f9dfd83dfbf..c86b9217d6f90c75259dd5d36bae742570cbde46 100644 (file)
@@ -1,3 +1,8 @@
+2003-05-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/10496
+       * g++.dg/warn/pmf1.C: New test.
+
 2003-05-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/4494
diff --git a/gcc/testsuite/g++.dg/warn/pmf1.C b/gcc/testsuite/g++.dg/warn/pmf1.C
new file mode 100644 (file)
index 0000000..013c21b
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+// Origin: benko@sztaki.hu
+
+// PR c++/10496: Incorrect pointer to member function diagnostics
+// for constant member functions.
+
+struct a
+{
+  int f() const;
+};
+
+
+int
+a::f() const
+{
+  int (a::* b)() const = &f; // { dg-error "&a::f" }
+}