aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-02-08 17:07:54 -0500
committerJason Merrill <jason@gcc.gnu.org>2016-02-08 17:07:54 -0500
commit1374a761eb55be67e49bb20ae051abb495b840a2 (patch)
tree55ed5f5dc37a358838fcf6fd9ebf04a1a1ef2539
parenta162f3af802f4f3dab5a53e6864600e6c38582d7 (diff)
downloadgcc-1374a761eb55be67e49bb20ae051abb495b840a2.zip
gcc-1374a761eb55be67e49bb20ae051abb495b840a2.tar.gz
gcc-1374a761eb55be67e49bb20ae051abb495b840a2.tar.bz2
re PR c++/69657 (abs() not inlined after including math.h)
PR c++/69657 * name-lookup.c (do_nonmember_using_decl): Leave anticipated built-ins alone. From-SVN: r233229
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/name-lookup.c29
-rw-r--r--gcc/testsuite/g++.dg/lookup/builtin6.C23
3 files changed, 45 insertions, 13 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f7a76ff..563a1b3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-08 Jason Merrill <jason@redhat.com>
+
+ PR c++/69657
+ * name-lookup.c (do_nonmember_using_decl): Leave anticipated
+ built-ins alone.
+
2016-02-08 Jakub Jelinek <jakub@redhat.com>
PR c++/59627
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 92d99aa..227d6f2 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -2583,15 +2583,6 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
decls.value = 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)
- && !DECL_HIDDEN_FRIEND_P (oldval))
- oldval = NULL_TREE;
-
if (decls.value)
{
/* Check for using functions. */
@@ -2610,6 +2601,10 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
{
tree new_fn = OVL_CURRENT (tmp);
+ /* Don't import functions that haven't been declared. */
+ if (DECL_ANTICIPATED (new_fn))
+ continue;
+
/* [namespace.udecl]
If a function declaration in namespace scope or block
@@ -2627,13 +2622,13 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
continue; /* this is a using decl */
else if (compparms_for_decl_and_using_decl (new_fn, old_fn))
{
- gcc_assert (!DECL_ANTICIPATED (old_fn)
- || DECL_HIDDEN_FRIEND_P (old_fn));
-
/* 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 (DECL_ANTICIPATED (old_fn)
+ && !DECL_HIDDEN_FRIEND_P (old_fn))
+ /* Ignore anticipated built-ins. */;
+ else if (decls_match (new_fn, old_fn))
break;
else
{
@@ -2669,6 +2664,14 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
}
else
{
+ /* If we're declaring a non-function and OLDVAL is an anticipated
+ built-in, just pretend it isn't there. */
+ if (oldval
+ && TREE_CODE (oldval) == FUNCTION_DECL
+ && DECL_ANTICIPATED (oldval)
+ && !DECL_HIDDEN_FRIEND_P (oldval))
+ oldval = NULL_TREE;
+
*newval = decls.value;
if (oldval && !decls_match (*newval, oldval))
error ("%qD is already declared in this scope", name);
diff --git a/gcc/testsuite/g++.dg/lookup/builtin6.C b/gcc/testsuite/g++.dg/lookup/builtin6.C
new file mode 100644
index 0000000..456ade7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/builtin6.C
@@ -0,0 +1,23 @@
+// PR c++/69657
+// { dg-options -fdump-tree-gimple }
+// { dg-final { scan-tree-dump "ABS_EXPR" "gimple" } }
+
+namespace foo
+{
+ inline double
+ abs(double x)
+ { return __builtin_fabs(x); }
+}
+using foo::abs;
+
+extern "C" int abs(int);
+
+namespace bar {
+ using ::abs;
+}
+
+int
+wrapper (int x)
+{
+ return bar::abs (x) + bar::abs(x);
+}