This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: ICE: malformed code gives ICE for &(C::m)
Jason Merrill <jason@redhat.com> writes:
| Hmm...we might be trying to support that in order to be bug-compatible with
| VC++; I know it allows a lot of sloppiness with pointers to members. But
| that should only happen with -fms-extensions anyway; let's give your patch
| a try.
Ouch, I forgot the -fms-extensions. This revision tries to
incorporate it along with your other suggestions.
| But please change your error message to tell the user something about how
| to fix their code, not just that something they did was wrong. Probably
| the simplest way to do this was tell them that a proper pointer-to-member
| is written "&C::m".
Thanks. In the case submitted by Mike, I suggest removing the surrounding
parenthesis. And I try to do the right thing i.e. setting PTRMEM_OK_P.
In the case of PR/2521, I suggest using a qualified-id. In that
typical case it is not easy to figure out what exactly what gets there
-- it turns out that in the particular exemple of PR/2521 we got a
TEMPLATE_ID_EXPR; but given that we don't always have canonical
representations throught out the compiler I don't know for sure the
nature of the things that may trigger that code path.
Further comments appreciated.
Thanks,
-- Gaby
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/ChangeLog,v
retrieving revision 1.2920
diff -p -r1.2920 ChangeLog
*** ChangeLog 5 Aug 2002 18:46:34 -0000 1.2920
--- ChangeLog 6 Aug 2002 14:23:14 -0000
***************
*** 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: typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.415
diff -p -r1.415 typeck.c
*** typeck.c 2 Aug 2002 11:57:22 -0000 1.415
--- typeck.c 6 Aug 2002 14:23:17 -0000
*************** build_x_unary_op (code, xarg)
*** 3794,3799 ****
--- 3794,3818 ----
}
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);