typeck.c (build_x_unary_op): Handle pointer-to-member.

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
This commit is contained in:
Gabriel Dos Reis 2002-08-07 00:38:00 +00:00 committed by Gabriel Dos Reis
parent 8d3e27d16b
commit 1e14c7f083
5 changed files with 48 additions and 0 deletions

View 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> 2002-08-05 Geoffrey Keating <geoffk@redhat.com>
* class.c: Don't include obstack.h. * class.c: Don't include obstack.h.

View File

@ -3794,6 +3794,25 @@ build_x_unary_op (code, xarg)
} }
if (code == ADDR_EXPR) 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) if (TREE_CODE (xarg) == OFFSET_REF)
{ {
ptrmem = PTRMEM_OK_P (xarg); ptrmem = PTRMEM_OK_P (xarg);

View 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> 2002-08-06 Neil Booth <neil@daikokuya.co.uk>
* gcc.dg/cpp/vararg3.c, gcc.dg/cpp/vararg4.c: New tests. * gcc.dg/cpp/vararg3.c, gcc.dg/cpp/vararg4.c: New tests.

View File

@ -2,6 +2,7 @@ Subdirectories:
abi Tests for ABI compatibility -- mangling, object layout, etc. abi Tests for ABI compatibility -- mangling, object layout, etc.
eh Tests for exception handling. eh Tests for exception handling.
expr Tests for expressions.
ext Tests for GNU language extensions. ext Tests for GNU language extensions.
inherit Tests for inheritance -- virtual functions, multiple inheritance, etc. inherit Tests for inheritance -- virtual functions, multiple inheritance, etc.
init Tests for initialization semantics, constructors/destructors, etc. init Tests for initialization semantics, constructors/destructors, etc.

View File

@ -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 "" "" }
}
};