]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
typeck.c (build_x_unary_op): Handle pointer-to-member.
authorGabriel Dos Reis <gdr@nerim.net>
Wed, 7 Aug 2002 00:38:00 +0000 (00:38 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Wed, 7 Aug 2002 00:38:00 +0000 (00:38 +0000)
cp/
* typeck.c (build_x_unary_op): Handle pointer-to-member.

testsuite/
* g++.dg/README (Subdirectories): Document new subdir expr.
* g++.dg/expr/pmf-1.C: New test.

From-SVN: r56082

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/README
gcc/testsuite/g++.dg/expr/pmf-1.C [new file with mode: 0644]

index ddadb9c87e2c84412e40d9974c8ad3ac73b8ff54..60b6cb239dcf38db1242b630b5db5e60ee272221 100644 (file)
@@ -1,3 +1,7 @@
+2002-08-06  Gabriel Dos Reis  <gdr@nerim.net>
+
+       * typeck.c (build_x_unary_op): Handle pointer-to-member.
+
 2002-08-05  Geoffrey Keating  <geoffk@redhat.com>
 
        * class.c: Don't include obstack.h.
index 965f3f4399d8468d9f5a5a3856ca003e12fb43e5..399005bc6910f85b1171c58c6fc0523b1820561e 100644 (file)
@@ -3794,6 +3794,25 @@ build_x_unary_op (code, xarg)
     }
   if (code == ADDR_EXPR)
     {
+      /*  A pointer to member-function can be formed only by saying
+         &X::mf.  */
+      if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
+         && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
+       {
+         if (TREE_CODE (xarg) != OFFSET_REF)
+           {
+             error ("invalid use of '%E' to form a pointer-to-member-function.  Use a qualified-id.",
+                    xarg);
+             return error_mark_node;
+           }
+         else
+           {
+             error ("parenthesis around '%E' cannot be used to form a pointer-to-member-function",
+                    xarg);
+             PTRMEM_OK_P (xarg) = 1;
+           }
+       }
+      
       if (TREE_CODE (xarg) == OFFSET_REF)
         {
           ptrmem = PTRMEM_OK_P (xarg);
index 55fd9a1aeb26a0ab819befa1974f927a0ba874de..0acf870252be3731c857d5065cfd77a24b8b40ac 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-07  Gabriel Dos Reis  <gdr@nerim.net>
+
+       * g++.dg/README (Subdirectories): Document new subdir expr.
+       * g++.dg/expr/pmf-1.C: New test.
+
 2002-08-06  Neil Booth  <neil@daikokuya.co.uk>
 
        * gcc.dg/cpp/vararg3.c, gcc.dg/cpp/vararg4.c: New tests.
index edf1d5a38a5349ae0e306ede88c50bd99818f9de..073913f2056c5a19697a546e02aaa0a8fe57c131 100644 (file)
@@ -2,6 +2,7 @@ Subdirectories:
 
 abi     Tests for ABI compatibility -- mangling, object layout, etc.
 eh      Tests for exception handling.
+expr     Tests for expressions.
 ext     Tests for GNU language extensions.
 inherit         Tests for inheritance -- virtual functions, multiple inheritance, etc.
 init    Tests for initialization semantics, constructors/destructors, etc.
diff --git a/gcc/testsuite/g++.dg/expr/pmf-1.C b/gcc/testsuite/g++.dg/expr/pmf-1.C
new file mode 100644 (file)
index 0000000..61457ec
--- /dev/null
@@ -0,0 +1,19 @@
+// C++ PR/2521
+// Copyright (C) 2002 Free Software Foundation
+// Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+// { dg-do compile }
+
+struct A 
+{
+  void f();
+  void foo(void (A::*)(int));       // { dg-error "candidate" "" }
+  template<typename T>
+    void g(T);
+  void h()
+  {
+    void (A::*p)() = &A::f;
+    void (A::*q)() = &(A::f);       // { dg-error "parenthesis" "" }
+    foo(&g<int>);                   // { dg-error "" "" }
+  }
+};