Commit 44fd0e80 by Ollie Wild Committed by Ollie Wild

re PR c++/31749 (ICE with invalid redeclaration of builtin)

	PR c++/31749

	gcc/cp/
	* name-lookup.c (do_nonmember_using_decl): Shift implicit type
	declarations into appropriate slots for comparison.  Fix type
	comparison.

	gcc/testsuite/
	* g++.dg/lookup/builtin3.C: New test.
	* g++.dg/lookup/builtin4.C: New test.
	* g++.dg/lookup/using19.C: New test.

From-SVN: r127600
parent 9ab78e53
2007-08-17 Ollie Wild <aaw@google.com>
PR c++/31749
* name-lookup.c (do_nonmember_using_decl): Shift implicit type
declarations into appropriate slots for comparison. Fix type
comparison.
2007-08-17 Paolo Carlini <pcarlini@suse.de> 2007-08-17 Paolo Carlini <pcarlini@suse.de>
PR c++/32112 PR c++/32112
......
...@@ -2099,6 +2099,20 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -2099,6 +2099,20 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
return; return;
} }
/* Shift the old and new bindings around so we're comparing class and
enumeration names to each other. */
if (oldval && DECL_IMPLICIT_TYPEDEF_P (oldval))
{
oldtype = oldval;
oldval = NULL_TREE;
}
if (decls.value && DECL_IMPLICIT_TYPEDEF_P (decls.value))
{
decls.type = decls.value;
decls.value = NULL_TREE;
}
/* It is impossible to overload a built-in function; any explicit /* It is impossible to overload a built-in function; any explicit
declaration eliminates the built-in declaration. So, if OLDVAL declaration eliminates the built-in declaration. So, if OLDVAL
is a built-in, then we can just pretend it isn't there. */ is a built-in, then we can just pretend it isn't there. */
...@@ -2108,14 +2122,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -2108,14 +2122,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
&& !DECL_HIDDEN_FRIEND_P (oldval)) && !DECL_HIDDEN_FRIEND_P (oldval))
oldval = NULL_TREE; oldval = NULL_TREE;
if (decls.value)
{
/* Check for using functions. */ /* Check for using functions. */
if (decls.value && is_overloaded_fn (decls.value)) if (is_overloaded_fn (decls.value))
{ {
tree tmp, tmp1; tree tmp, tmp1;
if (oldval && !is_overloaded_fn (oldval)) if (oldval && !is_overloaded_fn (oldval))
{ {
if (!DECL_IMPLICIT_TYPEDEF_P (oldval))
error ("%qD is already declared in this scope", name); error ("%qD is already declared in this scope", name);
oldval = NULL_TREE; oldval = NULL_TREE;
} }
...@@ -2189,6 +2204,9 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -2189,6 +2204,9 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
if (oldval && !decls_match (*newval, oldval)) if (oldval && !decls_match (*newval, oldval))
error ("%qD is already declared in this scope", name); error ("%qD is already declared in this scope", name);
} }
}
else
*newval = oldval;
if (decls.type && TREE_CODE (decls.type) == TREE_LIST) if (decls.type && TREE_CODE (decls.type) == TREE_LIST)
{ {
...@@ -2198,12 +2216,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype, ...@@ -2198,12 +2216,15 @@ do_nonmember_using_decl (tree scope, tree name, tree oldval, tree oldtype,
else else
{ {
*newtype = decls.type; *newtype = decls.type;
if (oldtype && *newtype && !same_type_p (oldtype, *newtype)) if (oldtype && *newtype && !decls_match (oldtype, *newtype))
{ error ("%qD is already declared in this scope", name);
error ("using declaration %qD introduced ambiguous type %qT",
name, oldtype);
return;
} }
/* If *newval is empty, shift any class or enumeration name down. */
if (!*newval)
{
*newval = *newtype;
*newtype = NULL_TREE;
} }
} }
......
2007-08-17 Ollie Wild <aaw@google.com>
PR c++/31749
* g++.dg/lookup/builtin3.C: New test.
* g++.dg/lookup/builtin4.C: New test.
* g++.dg/lookup/using19.C: New test.
2007-08-17 Paolo Carlini <pcarlini@suse.de> 2007-08-17 Paolo Carlini <pcarlini@suse.de>
PR c++/32190 PR c++/32190
// Copyright (C) 2007 Free Software Foundation
// Contributed by Ollie Wild <aaw@google.com>
// Origin: Volker Reichelt <reichelt@gcc.gnu.org>
// { dg-do compile }
// PR 31749: ICE with redeclaration of builtin
namespace std
{
union abort;
}
void abort();
using std::abort;
// Copyright (C) 2007 Free Software Foundation
// Contributed by Ollie Wild <aaw@google.com>
// Origin: Volker Reichelt <reichelt@gcc.gnu.org>
// { dg-do compile }
// PR 31749: ICE with redeclaration of builtin
namespace std
{
union abort;
}
union abort;
using std::abort; // { dg-error "" }
// Copyright (C) 2007 Free Software Foundation
// Contributed by Ollie Wild <aaw@google.com>
// { dg-do compile }
// C++ Standard, 7.3.3, clause 10:
// "Since a using-declaration is a declaration, the restrictions on
// declarations of the same name in the same declarative region (3.3) also
// apply to using-declarations."
namespace M
{
union A;
void B();
}
void A();
union B;
using M::A;
using M::B;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment