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]
Other format: [Raw text]

[C++ PATCH, committed] Fix incorrect pmf diagnostics (PR10496)


Hi

This patch fixes an incorrect diagnostics about invalid
pointer-to-member functions.  When such code appears in
const member, the 'this' pointer contains an extra const
qualifier.  We have to remove that qualifier when outputting
the diagnostics.

Tested on i686-pc-linux-gnu.  Committed to the trunk as obvious.

--Kriang


2003-05-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/10496
	* typeck.c (build_unary_op): Don't output const qualifier when
	output invalid pointer-to-member diagnostics.

2003-05-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/10496
	* g++.dg/warn/pmf1.C: New test.


diff -cprN gcc-main-save/gcc/cp/typeck.c gcc-main-new/gcc/cp/typeck.c
*** gcc-main-save/gcc/cp/typeck.c	Sun Apr 27 19:10:57 2003
--- gcc-main-new/gcc/cp/typeck.c	Mon May  5 21:37:28 2003
*************** build_unary_op (code, xarg, noconvert)
*** 4435,4446 ****
  
  	  if (! flag_ms_extensions)
  	    {
  	      if (current_class_type
  		  && TREE_OPERAND (arg, 0) == current_class_ref)
  		/* An expression like &memfn.  */
! 		pedwarn ("ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say `&%T::%D'", base, name);
  	      else
! 		pedwarn ("ISO C++ forbids taking the address of a bound member function to form a pointer to member function.  Say `&%T::%D'", base, name);
  	    }
  	  arg = build_offset_ref (base, name);
          }
--- 4435,4455 ----
  
  	  if (! flag_ms_extensions)
  	    {
+ 	      /* Inside constant member functions, the `this' pointer
+ 		 contains an extra const qualifier.  TYPE_MAIN_VARIANT
+ 		 is used here to remove this const from the diagnostics.  */
  	      if (current_class_type
  		  && TREE_OPERAND (arg, 0) == current_class_ref)
  		/* An expression like &memfn.  */
! 		pedwarn ("ISO C++ forbids taking the address of an unqualified"
! 			 " or parenthesized non-static member function to form"
! 			 " a pointer to member function.  Say `&%T::%D'",
! 			 TYPE_MAIN_VARIANT (base), name);
  	      else
! 		pedwarn ("ISO C++ forbids taking the address of a bound member"
! 			 " function to form a pointer to member function."
! 			 "  Say `&%T::%D'",
! 			 TYPE_MAIN_VARIANT (base), name);
  	    }
  	  arg = build_offset_ref (base, name);
          }
*************** build_x_compound_expr (list)
*** 4793,4799 ****
        /* the left-hand operand of a comma expression is like an expression
           statement: we should warn if it doesn't have any side-effects,
           unless it was explicitly cast to (void).  */
!       if ((extra_warnings || warn_unused_value)
             && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
                  && VOID_TYPE_P (TREE_TYPE (TREE_VALUE(list)))))
          warning("left-hand operand of comma expression has no effect");
--- 4802,4808 ----
        /* the left-hand operand of a comma expression is like an expression
           statement: we should warn if it doesn't have any side-effects,
           unless it was explicitly cast to (void).  */
!       if (warn_unused_value
             && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
                  && VOID_TYPE_P (TREE_TYPE (TREE_VALUE(list)))))
          warning("left-hand operand of comma expression has no effect");
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/warn/pmf1.C gcc-main-new/gcc/testsuite/g++.dg/warn/pmf1.C
*** gcc-main-save/gcc/testsuite/g++.dg/warn/pmf1.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/warn/pmf1.C	Mon May  5 20:43:09 2003
***************
*** 0 ****
--- 1,18 ----
+ // { dg-do compile }
+ 
+ // Origin: benko@sztaki.hu
+ 
+ // PR c++/10496: Incorrect pointer to member function diagnostics
+ // for constant member functions.
+ 
+ struct a
+ {
+   int f() const;
+ };
+ 
+ 
+ int
+ a::f() const
+ {
+   int (a::* b)() const = &f; // { dg-error "&a::f" }
+ }


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