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]

[PR c++/18838] back-port fix for PR c++/19367 to 3.4 branch


As it turns out, the fix for PR c++/19367 also fixed c++/18838, but
it's only in mainline.  A trivial backport to the 3.4 branch is below.
Tested on x86_64-linux-gnu.  I don't think this is not a regression,
but...  Ok for 3.4?

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/18838
	2005-01-30  Mark Mitchell  <mark@codesourcery.com>
	PR c++/19367
	* name-lookup.c (do_nonmember_using_decl): Avoid overloading
	builtin declarations.

Index: gcc/cp/name-lookup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/name-lookup.c,v
retrieving revision 1.34.2.20
diff -u -p -r1.34.2.20 name-lookup.c
--- gcc/cp/name-lookup.c 8 Dec 2004 10:53:10 -0000 1.34.2.20
+++ gcc/cp/name-lookup.c 9 Feb 2005 18:18:58 -0000
@@ -1,5 +1,5 @@
 /* Definitions for C++ name lookup routines.
-   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
@@ -2177,6 +2177,15 @@ do_nonmember_using_decl (tree scope, tre
 	  oldval = NULL_TREE;
 	}
 
+      /* It is impossible to overload a built-in function; any
+	 explicit declaration eliminates the built-in declaration.
+	 So, if OLDVAL is a built-in, then we can just pretend it
+	 isn't there.  */
+      if (oldval 
+	  && TREE_CODE (oldval) == FUNCTION_DECL
+	  && DECL_ANTICIPATED (oldval))
+	oldval = NULL_TREE;
+
       *newval = oldval;
       for (tmp = decls.value; tmp; tmp = OVL_NEXT (tmp))
 	{
@@ -2200,27 +2209,19 @@ do_nonmember_using_decl (tree scope, tre
 	      else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
 		  		  TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
 		{
+		  if (DECL_ANTICIPATED (old_fn))
+		    abort ();
+
 	          /* There was already a non-using declaration in
 		     this scope with the same parameter types. If both
 	             are the same extern "C" functions, that's ok.  */
                   if (decls_match (new_fn, old_fn))
-		    {
-		      /* If the OLD_FN was a builtin, there is now a
-			 real declaration.  */
-		      if (DECL_ANTICIPATED (old_fn))
-			DECL_ANTICIPATED (old_fn) = 0;
+		    break;
+		  else
+ 		    {
+		      error ("%D is already declared in this scope", name);
 		      break;
 		    }
-		  else if (!DECL_ANTICIPATED (old_fn))
-		    {
-		      /* If the OLD_FN was really declared, the
-			 declarations don't match.  */
-		      error ("`%D' is already declared in this scope", name);
-		      break;
-		    }
-
-		  /* If the OLD_FN was not really there, just ignore
-		     it and keep going.  */
 		}
 	    }
 
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/18838
	* g++.dg/lookup/builtin2.C: New test.
	2005-01-30  Mark Mitchell  <mark@codesourcery.com>
	PR c++/19367
	* g++.dg/lookup/builtin1.C: New test.

Index: gcc/testsuite/g++.dg/lookup/builtin1.C
===================================================================
RCS file: gcc/testsuite/g++.dg/lookup/builtin1.C
diff -N gcc/testsuite/g++.dg/lookup/builtin1.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/lookup/builtin1.C 9 Feb 2005 18:19:13 -0000
@@ -0,0 +1,12 @@
+// PR c++/19367
+// { dg-do link } 
+
+void abort (void) { throw 3; }
+
+namespace std { using ::abort; }
+
+int main ()
+{
+  using std::abort;
+  abort();
+}
Index: gcc/testsuite/g++.dg/lookup/builtin2.C
===================================================================
RCS file: gcc/testsuite/g++.dg/lookup/builtin2.C
diff -N gcc/testsuite/g++.dg/lookup/builtin2.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/lookup/builtin2.C 9 Feb 2005 18:19:13 -0000
@@ -0,0 +1,25 @@
+// PR c++/18838
+// { dg-do compile }
+
+extern "C" {
+  extern double fabs (double __x) throw () __attribute__ ((__const__));
+
+  __inline double
+  fabs (double __x) throw () { return __builtin_fabs (__x); }
+}
+
+double fail_me(double __x) { return fabs(__x); }
+
+namespace std
+{
+  using ::fabs;
+}
+
+typedef double (*realfn) (double);
+
+using std::fabs;
+
+int main ()
+{
+  realfn myfn = fabs;
+}
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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