Commit 91b1ca65 by Mark Mitchell Committed by Mark Mitchell

re PR c++/20293 (Wrong diagnostic for ambiguous access)

	PR c++/20293
	* cxx-pretty-print.c (pp_cxx_statement): Print qualifying scopes
	for namespaces.
	(pp_cxx_original_namespace_definition): Likewise.
	* name-lookup.c (ambiguous_decl): Don't issue error messages;
	instead return lists of ambiguous candidates.
	(select_decl): Handle ambiguous namespace lookups.
	* parser.c (cp_token): Add ambiguous_p.
	(cp_lexer_get_preprocessor_token): Set it.
	(cp_parser_diagnose_invalid_type_name): Avoid duplicate messages
	when a qualified name uses an invalid scope. 
	(cp_parser_primary_expression): Print ambiguous candidates.
	(cp_parser_type_parameter): Adjust comment to reflect new
	parameter name for cp_parser_lookup_name.
	(cp_parser_template_argument): Likewise.
	(cp_parser_elaborated_type_specifier): Likewise.
	(cp_parser_namespace_name): Likewise.
	(cp_parser_class_name): Print ambiguous candidates.
	(cp_parser_lookup_name): Rename ambiguous_p parameter to
	ambiguous_decls.  Use it to return a list of ambiguous candiates
	when a lookup is ambiguous.
	(cp_parser_lookup_name_simple): Adjust comment to reflect new
	parameter name for cp_parser_lookup_name.
	
	PR c++/20293
	* g++.dg/parse/ambig4.C: New test.
	* g++.dg/tc1/dr101.C: Adjust error markers.
	* g++.dg/lookup/strong-using-2.C: Likewise.
	* g++.dg/lookup/ambig5.C: Likewise.
	* g++.dg/lookup/ambig4.C: Likewise.
	* g++.dg/parse/crash22.C: Likewise.

From-SVN: r106879
parent 43258b67
2005-11-13 Mark Mitchell <mark@codesourcery.com>
PR c++/20293
* cxx-pretty-print.c (pp_cxx_statement): Print qualifying scopes
for namespaces.
(pp_cxx_original_namespace_definition): Likewise.
* name-lookup.c (ambiguous_decl): Don't issue error messages;
instead return lists of ambiguous candidates.
(select_decl): Handle ambiguous namespace lookups.
* parser.c (cp_token): Add ambiguous_p.
(cp_lexer_get_preprocessor_token): Set it.
(cp_parser_diagnose_invalid_type_name): Avoid duplicate messages
when a qualified name uses an invalid scope.
(cp_parser_primary_expression): Print ambiguous candidates.
(cp_parser_type_parameter): Adjust comment to reflect new
parameter name for cp_parser_lookup_name.
(cp_parser_template_argument): Likewise.
(cp_parser_elaborated_type_specifier): Likewise.
(cp_parser_namespace_name): Likewise.
(cp_parser_class_name): Print ambiguous candidates.
(cp_parser_lookup_name): Rename ambiguous_p parameter to
ambiguous_decls. Use it to return a list of ambiguous candiates
when a lookup is ambiguous.
(cp_parser_lookup_name_simple): Adjust comment to reflect new
parameter name for cp_parser_lookup_name.
2005-11-12 Jakub Jelinek <jakub@redhat.com> 2005-11-12 Jakub Jelinek <jakub@redhat.com>
PR c++/24780 PR c++/24780
......
...@@ -1514,6 +1514,8 @@ pp_cxx_statement (cxx_pretty_printer *pp, tree t) ...@@ -1514,6 +1514,8 @@ pp_cxx_statement (cxx_pretty_printer *pp, tree t)
case USING_STMT: case USING_STMT:
pp_cxx_identifier (pp, "using"); pp_cxx_identifier (pp, "using");
pp_cxx_identifier (pp, "namespace"); pp_cxx_identifier (pp, "namespace");
if (DECL_CONTEXT (t))
pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t)); pp_cxx_qualified_id (pp, USING_STMT_NAMESPACE (t));
break; break;
...@@ -1701,6 +1703,8 @@ static void ...@@ -1701,6 +1703,8 @@ static void
pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t) pp_cxx_original_namespace_definition (cxx_pretty_printer *pp, tree t)
{ {
pp_cxx_identifier (pp, "namespace"); pp_cxx_identifier (pp, "namespace");
if (DECL_CONTEXT (t))
pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
if (DECL_NAME (t)) if (DECL_NAME (t))
pp_cxx_unqualified_id (pp, t); pp_cxx_unqualified_id (pp, t);
pp_cxx_whitespace (pp); pp_cxx_whitespace (pp);
...@@ -1723,10 +1727,15 @@ static void ...@@ -1723,10 +1727,15 @@ static void
pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t) pp_cxx_namespace_alias_definition (cxx_pretty_printer *pp, tree t)
{ {
pp_cxx_identifier (pp, "namespace"); pp_cxx_identifier (pp, "namespace");
if (DECL_CONTEXT (t))
pp_cxx_nested_name_specifier (pp, DECL_CONTEXT (t));
pp_cxx_unqualified_id (pp, t); pp_cxx_unqualified_id (pp, t);
pp_cxx_whitespace (pp); pp_cxx_whitespace (pp);
pp_equal (pp); pp_equal (pp);
pp_cxx_whitespace (pp); pp_cxx_whitespace (pp);
if (DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)))
pp_cxx_nested_name_specifier (pp,
DECL_CONTEXT (DECL_NAMESPACE_ALIAS (t)));
pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t)); pp_cxx_qualified_id (pp, DECL_NAMESPACE_ALIAS (t));
pp_cxx_semicolon (pp); pp_cxx_semicolon (pp);
} }
......
...@@ -3400,20 +3400,9 @@ ambiguous_decl (tree name, struct scope_binding *old, cxx_binding *new, ...@@ -3400,20 +3400,9 @@ ambiguous_decl (tree name, struct scope_binding *old, cxx_binding *new,
old->value = merge_functions (old->value, val); old->value = merge_functions (old->value, val);
else else
{ {
/* Some declarations are functions, some are not. */ old->value = tree_cons (NULL_TREE, old->value,
if (flags & LOOKUP_COMPLAIN) build_tree_list (NULL_TREE, new->value));
{ TREE_TYPE (old->value) = error_mark_node;
/* If we've already given this error for this lookup,
old->value is error_mark_node, so let's not
repeat ourselves. */
if (old->value != error_mark_node)
{
error ("use of %qD is ambiguous", name);
error (" first declared as %q+#D here", old->value);
}
error (" also declared as %q+#D here", val);
}
old->value = error_mark_node;
} }
} }
/* ... and copy the type. */ /* ... and copy the type. */
...@@ -3609,7 +3598,8 @@ select_decl (const struct scope_binding *binding, int flags) ...@@ -3609,7 +3598,8 @@ select_decl (const struct scope_binding *binding, int flags)
if (LOOKUP_NAMESPACES_ONLY (flags)) if (LOOKUP_NAMESPACES_ONLY (flags))
{ {
/* We are not interested in types. */ /* We are not interested in types. */
if (val && TREE_CODE (val) == NAMESPACE_DECL) if (val && (TREE_CODE (val) == NAMESPACE_DECL
|| TREE_CODE (val) == TREE_LIST))
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE); POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
} }
......
2005-11-13 Mark Mitchell <mark@codesourcery.com>
PR c++/20293
* g++.dg/parse/ambig4.C: New test.
* g++.dg/tc1/dr101.C: Adjust error markers.
* g++.dg/lookup/strong-using-2.C: Likewise.
* g++.dg/lookup/ambig5.C: Likewise.
* g++.dg/lookup/ambig4.C: Likewise.
* g++.dg/parse/crash22.C: Likewise.
2005-11-14 Hans-Peter Nilsson <hp@axis.com> 2005-11-14 Hans-Peter Nilsson <hp@axis.com>
* gcc.dg/pr19340.c: Skip for mmix-*-* and cris-*-*. * gcc.dg/pr19340.c: Skip for mmix-*-* and cris-*-*.
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
namespace N namespace N
{ {
int i; // { dg-error "declared" } int i; // { dg-error "i" }
} }
int i; // { dg-error "declared" } int i; // { dg-error "i" }
using namespace N; using namespace N;
void foo() { i; } // { dg-error "in this scope|ambiguous" } void foo() { i; } // { dg-error "ambiguous" }
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
namespace N namespace N
{ {
namespace M {} // { dg-error "declared" } namespace M {} // { dg-error "M" }
} }
namespace M {} // { dg-error "declared" } namespace M {} // { dg-error "M" }
using namespace N; using namespace N;
using namespace M; // { dg-error "namespace-name|ambiguous" } using namespace M; // { dg-error "namespace-name|ambiguous" }
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
// { dg-do compile } // { dg-do compile }
namespace foo_impl { namespace foo_impl {
class T; // { dg-error "first declared" "" } class T; // { dg-error "T" "" }
} }
namespace bar_impl { namespace bar_impl {
class T; // { dg-error "also declared" "" } class T; // { dg-error "T" "" }
} }
namespace foo { namespace foo {
using namespace foo_impl __attribute__((strong)); using namespace foo_impl __attribute__((strong));
......
// PR c++/20293
namespace hide { // { dg-error "hide" }
int k;
}
namespace {
int i;
namespace hide { // { dg-error "hide" }
int j;
}
}
void F(int) {}
int main() {
F(hide::j); // { dg-error "ambiguous" }
}
...@@ -4,17 +4,17 @@ ...@@ -4,17 +4,17 @@
// PR 19030: ICE // PR 19030: ICE
// Origin: Volker Reichelt <reichelt@gcc.gnu.org> // Origin: Volker Reichelt <reichelt@gcc.gnu.org>
struct A; struct A; // { dg-error "A" }
namespace N namespace N
{ {
struct A; struct A; // { dg-error "A" }
} }
using namespace N; using namespace N;
int A::i; // { dg-error "not been declared|declared here" "" } int A::i; // { dg-error "ambiguous|declared here" "" }
int A::i; // { dg-error "not been declared|redefinition of" "" } int A::i; // { dg-error "ambiguous|redefinition of" "" }
namespace N namespace N
{ {
......
...@@ -17,10 +17,10 @@ namespace Test1 { ...@@ -17,10 +17,10 @@ namespace Test1 {
namespace Test2 { namespace Test2 {
typedef unsigned int X; // { dg-bogus "declared" "" { xfail *-*-* } } typedef unsigned int X; // { dg-bogus "X" "" { xfail *-*-* } }
extern "C" int f2(); extern "C" int f2();
namespace N { namespace N {
typedef unsigned int X; // { dg-bogus "declared" "" { xfail *-*-* } } typedef unsigned int X; // { dg-bogus "X" "" { xfail *-*-* } }
extern "C" int f2(); extern "C" int f2();
} }
using namespace N; using namespace N;
......
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