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]

Re: [C++ PATCH] Fix extern "C" function and namespace handling


On 07 Oct 2000 at 02:29 (-0400), brent@rcfile.org wrote:
| On 07 Oct 2000 at 01:25 (-0400), brent@rcfile.org wrote:
| | On 06 Oct 2000 at 20:24 (-0700), Kriang Lerdsuwanakij wrote:
| | | Hi
| | | 
| | | The included patch fix the extern "C" function and namespace handling
| | | to comply with 7.5p6 of the standard.  Declarations for such functions
| | | in different namespaces are treated as the same function.  One
| | | definition rule is also enforced for these functions across the
| | | namespaces.
| | 
| | nice! works afaict.
| 
| well, mostly :) 
| The following does not compile -- it should.
| 
| namespace _C_ { 
|   extern "C" int abs(int a); 
| }
| using ::_C_::abs;
| 
| int main()
| {
|   return 0;
| }
| 
| dust$ Compile n.cc
| g++ -g -Wall -I. -DDEBUG_ASSERT n.cc -o n 
| n.cc:4: `abs' is already declared in this scope

the attached patch to cp/decl2.c allows the code above to compile.
I'm not sure if it is sane, but I'll throw it in the mix. basically,
all I did was reverse the order of the tests in 
do_nonmember_using_decl() to allow the duplicate_decls() case to break
before testing the overloaded function.

  brent

-- 
All opinions expressed are My own, unless otherwise attributed. In
presenting facts, I expressly reserve the right to be Wrong. Portions
of this message authored by Me are subject to the Free Thought License.
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.401
diff -c -p -3 -r1.401 decl2.c
*** decl2.c	2000/10/05 08:41:43	1.401
--- decl2.c	2000/10/07 07:10:11
*************** do_nonmember_using_decl (scope, name, ol
*** 5202,5208 ****
  	    {
  	      tree old_fn = OVL_CURRENT (tmp1);
  
! 	      if (!OVL_USED (tmp1)
  		  && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
  				TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
  		{
--- 5202,5212 ----
  	    {
  	      tree old_fn = OVL_CURRENT (tmp1);
  
! 	      if (duplicate_decls (new_fn, old_fn))
! 		/* We're re-using something we already used 
! 		   before.  We don't need to add it again.  */ 
! 		break;
!               else if (!OVL_USED (tmp1)
  		  && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
  				TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
  		{
*************** do_nonmember_using_decl (scope, name, ol
*** 5212,5221 ****
  			    name);
  		  break;
  		}
- 	      else if (duplicate_decls (new_fn, old_fn))
- 		/* We're re-using something we already used 
- 		   before.  We don't need to add it again.  */ 
- 		break;
  	    }
  
  	  /* If we broke out of the loop, there's no reason to add
--- 5216,5221 ----

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