C++ PATCH: Fix PR/2213

Gabriel Dos Reis gdr@nerim.net
Sun Aug 4 10:05:00 GMT 2002


This patchlet fixes PR 2213 by rejecting the invalid cast -- as
suggested by Mark in the audit trail.

Bootstrapped and tested on an i686-pc-linux.  No regression.

OK for mainline?

-- Gaby

cp/

2002-08-04  Gabriel Dos Reis  <gdr@nerim.net>

	Fix PR/2213
	* cvt.c (cp_convert_to_pointer): Reject conversions from integral
	expressions to pointer-to-data-member or pointer-to-member-functions.

testsuite/

2002-08-04  Gabriel Dos Reis  <gdr@nerim.net>

	* g++.dg/other/conversion1.C: New test.

Index: cp/cvt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cvt.c,v
retrieving revision 1.120
diff -p -r1.120 cvt.c
*** cp/cvt.c	1 Aug 2002 04:46:18 -0000	1.120
--- cp/cvt.c	4 Aug 2002 16:56:35 -0000
*************** cp_convert_to_pointer (type, expr, force
*** 256,261 ****
--- 256,267 ----
        force_fit_type (expr, 0);
        return expr;
      }
+   else if ((TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type))
+ 	   && INTEGRAL_CODE_P (form))
+     {
+       error ("invalid conversion from '%T' to '%T'", intype, type);
+       return error_mark_node;
+     }
  
    if (INTEGRAL_CODE_P (form))
      {

Index: testsuite/g++.dg/other/conversion1.C
===================================================================
RCS file: testsuite/g++.dg/other/conversion1.C
diff -N testsuite/g++.dg/other/conversion1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/other/conversion1.C	4 Aug 2002 16:56:40 -0000
***************
*** 0 ****
--- 1,17 ----
+ // PR C++/2213
+ // Origin: philippeb@corel.com
+ // Copyright (C), 2002 Free Software Foundation
+ // Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
+ 
+ // { dg-do compile } 
+  
+ class QObject
+ {
+ };
+ 
+ int main()
+ {
+   long long m;
+   
+   (void (QObject::*)()) m;    // { dg-error "invalid conversion" "" }
+ }



More information about the Gcc-patches mailing list