This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

taking address of a non-static or bound method


Hello,

 till egcs 1.1.2 it was possible with C++ to take the address of a
non-static member function with a syntax like `&method' or
`&object->method'.

 Now egcs-19990718 issues a warning and requires me to write
`&class::method' in both cases. Since the old behaviour was a neat feature
and most of my programs depend on it, I've added a `ill-pmf', `no-ill-pmf'
option to suppress the warning.

  Bye,
    Mark

    TOAD -- A Simple and Powerful C++ GUI Toolkit for X-Windows
            Freely available at http://toad.home.pages.de/
    /OO\
__(/_--_\)___________ Mark-André Hopf <hopf@informatik.uni-rostock.de>
diff -rcp egcs-19990718/gcc/cp/ChangeLog egcs-19990718-patched/gcc/cp/ChangeLog
*** egcs-19990718/gcc/cp/ChangeLog	Sun Jul 18 07:51:48 1999
--- egcs-19990718-patched/gcc/cp/ChangeLog	Thu Jul 29 14:42:39 1999
***************
*** 1,3 ****
--- 1,11 ----
+ 1999-07-29  Mark-Andre Hopf  <hopf@informatik.uni-rostock.de>
+ 
+ 	* decl2.c (lang_decode_option): Added -W{no-,}ill-pmf.
+ 	* lang-options.h: Likewise.
+ 	* decl2.c (warn_ill_pmf): Define
+ 	* cp-tree.h: Declare it.
+ 	* typeck.c (build_unary_op): Suppress warning
+ 
  Sat Jul 17 23:50:47 1999  Jeffrey A Law  (law@cygnus.com)
  
  	* Makefile.in (INTERFACE): Bump to 2.
diff -rcp egcs-19990718/gcc/cp/cp-tree.h egcs-19990718-patched/gcc/cp/cp-tree.h
*** egcs-19990718/gcc/cp/cp-tree.h	Tue Jun 15 18:48:20 1999
--- egcs-19990718-patched/gcc/cp/cp-tree.h	Thu Jul 29 14:19:22 1999
*************** extern int warn_nonvdtor;
*** 468,473 ****
--- 468,478 ----
  
  extern int warn_pmf2ptr;
  
+ /* Non-zero means warn when trying to take the address of a unique non-static
+    member function */
+ 
+ extern int warn_ill_pmf;
+ 
  /* Nonzero means warn about violation of some Effective C++ style rules.  */
  
  extern int warn_ecpp;
diff -rcp egcs-19990718/gcc/cp/decl2.c egcs-19990718-patched/gcc/cp/decl2.c
*** egcs-19990718/gcc/cp/decl2.c	Wed Jul  7 02:32:42 1999
--- egcs-19990718-patched/gcc/cp/decl2.c	Thu Jul 29 13:39:36 1999
*************** int warn_synth;
*** 316,321 ****
--- 316,326 ----
     into a pointer to (void or function).  */
  int warn_pmf2ptr = 1;
  
+ /* Non-zero means warn when we're trying to take the address of a unique 
+    non-static member function. */
+ 
+ int warn_ill_pmf = 1;
+ 
  /* Nonzero means warn about violation of some Effective C++ style rules.  */
  
  int warn_ecpp;
*************** lang_decode_option (argc, argv)
*** 726,731 ****
--- 731,738 ----
  	warn_synth = setting;
        else if (!strcmp (p, "pmf-conversions"))
  	warn_pmf2ptr = setting;
+       else if (!strcmp (p, "ill-pmf"))
+ 	warn_ill_pmf = setting;
        else if (!strcmp (p, "effc++"))
  	warn_ecpp = setting;
        else if (!strcmp (p, "sign-promo"))
diff -rcp egcs-19990718/gcc/cp/lang-options.h egcs-19990718-patched/gcc/cp/lang-options.h
*** egcs-19990718/gcc/cp/lang-options.h	Wed Apr 14 07:34:55 1999
--- egcs-19990718-patched/gcc/cp/lang-options.h	Thu Jul 29 13:40:29 1999
*************** DEFINE_LANG_NAME ("C++")
*** 122,127 ****
--- 122,129 ----
    { "-Wno-synth", "" },
    { "-Wpmf-conversions", "" },
    { "-Wno-pmf-conversions", "Don't warn when type converting pointers to member functions" },
+   { "-Will-pmf", "" },
+   { "-Wno-ill-pmf", "Don't warn when trying to take the address of a unique non-static member function" },
    { "-Weffc++", "Warn about violations of Effective C++ style rules" },
    { "-Wno-effc++", "" },
    { "-Wsign-promo", "Warn when overload promotes from unsigned to signed" },
diff -rcp egcs-19990718/gcc/cp/typeck.c egcs-19990718-patched/gcc/cp/typeck.c
*** egcs-19990718/gcc/cp/typeck.c	Fri May 21 17:44:03 1999
--- egcs-19990718-patched/gcc/cp/typeck.c	Thu Jul 29 14:16:53 1999
*************** build_unary_op (code, xarg, noconvert)
*** 4702,4719 ****
  	     member function.  This is ill-formed, but let's try to DTRT.  */
  	  tree base, name;
  
- 	  if (current_class_type
- 	      && TREE_OPERAND (arg, 0) == current_class_ref)
- 	    /* An expression like &memfn.  */
- 	    pedwarn ("taking the address of a non-static member function");
- 	  else
- 	    pedwarn ("taking the address of a bound member function");
- 
  	  base = TREE_TYPE (TREE_OPERAND (arg, 0));
  	  name = DECL_NAME (OVL_CURRENT (TREE_OPERAND (arg, 1)));
  
! 	  cp_pedwarn ("  to form a pointer to member function, say `&%T::%D'",
! 		      base, name);
  	  arg = build_offset_ref (base, name);
  	}
  
--- 4702,4722 ----
  	     member function.  This is ill-formed, but let's try to DTRT.  */
  	  tree base, name;
  
  	  base = TREE_TYPE (TREE_OPERAND (arg, 0));
  	  name = DECL_NAME (OVL_CURRENT (TREE_OPERAND (arg, 1)));
  
! 	  if (warn_ill_pmf)
! 	    {
! 	      if (current_class_type
! 		  && TREE_OPERAND (arg, 0) == current_class_ref)
! 		/* An expression like &memfn.  */
! 		pedwarn ("taking the address of a non-static member function");
! 	      else
! 		/* An expression like &obj->memfn */
! 		pedwarn ("taking the address of a bound member function");
! 	      cp_pedwarn ("  to form a pointer to member function, say `&%T::%D'",
! 			  base, name);
! 	    }
  	  arg = build_offset_ref (base, name);
  	}
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]