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]

C++ PATCH: extern "C" and namespaces



This patch allows code like:

  + extern "C" void f ();
  + 
  + namespace N {
  + extern "C" void f ();
  + }
  + 
  + using N::f;

This is legal, only because both functions are `extern "C"'.  This
shows up in the V3 backwards-compatibility headers.  There are two
functions named `remove' in the `std' namespace; the stdio function
and the algorithm template.  If you include plain <stdio.h>, then you
already have a `remove' in your global namespace, so including
<algo.h> would cause an error.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-11-04  Mark Mitchell  <mark@codesourcery.com>

	* decl2.c (do_nonmember_using_decl): Allow `extern "C"'
	declarations from different namespaces to be combined.

Index: testsuite/g++.old-deja/g++.ns/using14.C
===================================================================
RCS file: using14.C
diff -N using14.C
*** /dev/null	Tue May  5 13:32:27 1998
--- using14.C	Sat Nov  4 10:46:06 2000
***************
*** 0 ****
--- 1,15 ----
+ // Build don't link:
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+ 
+ extern "C" void f ();
+ 
+ namespace N {
+ extern "C" void f ();
+ }
+ 
+ using N::f;
+ 
+ void g ()
+ {
+   f ();
+ }
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.407
diff -c -p -r1.407 decl2.c
*** decl2.c	2000/10/31 01:30:58	1.407
--- decl2.c	2000/11/04 18:46:23
*************** do_nonmember_using_decl (scope, name, ol
*** 5204,5213 ****
  		  && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
  				TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
  		{
! 		  /* There was already a non-using declaration in
! 		     this scope with the same parameter types.  */
! 		  cp_error ("`%D' is already declared in this scope",
! 			    name);
  		  break;
  		}
  	      else if (duplicate_decls (new_fn, old_fn))
--- 5204,5215 ----
  		  && compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
  				TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
  		{
! 		  if (!(DECL_EXTERN_C_P (new_fn)
! 			&& DECL_EXTERN_C_P (old_fn)))
! 		    /* There was already a non-using declaration in
! 		       this scope with the same parameter types.  */
! 		    cp_error ("`%D' is already declared in this scope",
! 			      name);
  		  break;
  		}
  	      else if (duplicate_decls (new_fn, old_fn))

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