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 for 3.4/4.0] Fix PR19375 (duplicate access check errormessage)


Hi

This patch fixes a minor regression on 3.4 and 4.0 (PR19375)
where we produce duplicate error messages for failed access check.
The testcase for this PR is reproduced below:

  class A { int i; };
  class B : public A { int f() { return i; } };

Here the 'i' in the 'return i;' statement, we first perform
name lookup and display message that 'A::i' is private and inaccessible
(by check_accessibility_of_qualified_id called from cp_parser_lookup_name).
We later convert the 'i' into representatin 'this->i' and the same
error message is produced (by finish_non_static_data_member).

I fix it by disabling access checking around the
finish_non_static_data_member call so that the second error is no longer
produced.  There is no testcase in the patch since I don't think we
can check whether an error message is duplicate in the testsuite yet.

Tested on i686-pc-linux-gnu. OK for 3.4 and mainline?

--Kriang
2005-01-17  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/19375
	* semantics.c (finish_id_expression): Disable access checking for
	already lookuped FIELD_DECL.


diff -cprN gcc-main-save/gcc/cp/semantics.c gcc-main-new/gcc/cp/semantics.c
*** gcc-main-save/gcc/cp/semantics.c	Wed Jan 12 18:30:33 2005
--- gcc-main-new/gcc/cp/semantics.c	Sat Jan 15 00:36:44 2005
*************** finish_id_expression (tree id_expression
*** 2633,2641 ****
  	  /* The same is true for FIELD_DECL, but we also need to
  	     make sure that the syntax is correct.  */
  	  else if (TREE_CODE (decl) == FIELD_DECL)
! 	    return finish_non_static_data_member
! 		     (decl, current_class_ref,
! 		      /*qualifying_scope=*/NULL_TREE);
  	  return id_expression;
  	}
  
--- 2633,2649 ----
  	  /* The same is true for FIELD_DECL, but we also need to
  	     make sure that the syntax is correct.  */
  	  else if (TREE_CODE (decl) == FIELD_DECL)
! 	    {
! 	      /* Since SCOPE is NULL here, this is an unqualified name.
! 		 Access checking has been performed during name lookup
! 		 already.  Turn off checking to avoid duplicate errors.  */
! 	      push_deferring_access_checks (dk_no_check);
! 	      decl = finish_non_static_data_member
! 		       (decl, current_class_ref,
! 			/*qualifying_scope=*/NULL_TREE);
! 	      pop_deferring_access_checks ();
! 	      return decl;
! 	    }
  	  return id_expression;
  	}
  
*************** finish_id_expression (tree id_expression
*** 2700,2707 ****
  	    }
  	}
        else if (TREE_CODE (decl) == FIELD_DECL)
! 	decl = finish_non_static_data_member (decl, current_class_ref,
! 					      /*qualifying_scope=*/NULL_TREE);
        else if (is_overloaded_fn (decl))
  	{
  	  tree first_fn = OVL_CURRENT (decl);
--- 2708,2722 ----
  	    }
  	}
        else if (TREE_CODE (decl) == FIELD_DECL)
! 	{
! 	  /* Since SCOPE is NULL here, this is an unqualified name.
! 	     Access checking has been performed during name lookup
! 	     already.  Turn off checking to avoid duplicate errors.  */
! 	  push_deferring_access_checks (dk_no_check);
! 	  decl = finish_non_static_data_member (decl, current_class_ref,
! 						/*qualifying_scope=*/NULL_TREE);
! 	  pop_deferring_access_checks ();
! 	}
        else if (is_overloaded_fn (decl))
  	{
  	  tree first_fn = OVL_CURRENT (decl);

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