aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-02-28 08:26:41 +0000
committerJakub Jelinek <jakub@redhat.com>2005-02-28 08:26:41 +0000
commit3e76c270e1ce22f58f1f3b67768e7f1fa2a12c22 (patch)
treecf93be3c240413ea67052a493b8e8cd381c4e2e8
parent5d4a11650166bb5030f7952e5b35dfc38b036790 (diff)
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. 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. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-3_4-rhl-branch@95657 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/name-lookup.c31
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/lookup/builtin2.C25
4 files changed, 57 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 547b561457d..9411ae3a962 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2005-02-09 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.
+
2005-02-21 Alexandre Oliva <aoliva@redhat.com>
PR c++/20028
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 80f4c2946c2..50313f857ed 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -2177,6 +2177,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
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, tree name, tree oldval, tree oldtype,
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. */
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 45b3ea5e359..353c94f2835 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2005-02-09 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.
+
2005-02-21 Alexandre Oliva <aoliva@redhat.com>
PR c++/20028
diff --git a/gcc/testsuite/g++.dg/lookup/builtin2.C b/gcc/testsuite/g++.dg/lookup/builtin2.C
new file mode 100644
index 00000000000..ca9517ddc3e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/builtin2.C
@@ -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;
+}