Hi,
the main issue in the bug report is luckily already fixed in mainline
and 4.9 (had to do with a commit of mine ;( but I think we can do a
little better in the diagnostic: avoid the final redundant "does not
name a type" error after the error message about ambiguity. Tested
x86_64-linux.
Thanks,
Paolo.
//////////////////
/cp
2014-05-16 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51640
* parser.c (cp_parser_diagnose_invalid_type_name): Early return
when cp_parser_lookup_name sets ambiguous_decls.
/testsuite
2014-05-16 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51640
* g++.dg/parse/error54.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 210512)
+++ cp/parser.c (working copy)
@@ -2880,13 +2880,21 @@ cp_parser_diagnose_invalid_type_name (cp_parser *p
tree scope, tree id,
location_t location)
{
- tree decl, old_scope;
+ tree decl, old_scope, ambiguous_decls;
cp_parser_commit_to_tentative_parse (parser);
/* Try to lookup the identifier. */
old_scope = parser->scope;
parser->scope = scope;
- decl = cp_parser_lookup_name_simple (parser, id, location);
+ decl = cp_parser_lookup_name (parser, id, none_type,
+ /*is_template=*/false,
+ /*is_namespace=*/false,
+ /*check_dependency=*/true,
+ &ambiguous_decls, location);
parser->scope = old_scope;
+ if (ambiguous_decls)
+ /* If the lookup was ambiguous, an error will already have
+ been issued. */
+ return;
/* If the lookup found a template-name, it means that the user forgot
to specify an argument list. Emit a useful error message. */
if (TREE_CODE (decl) == TEMPLATE_DECL)
Index: testsuite/g++.dg/parse/error54.C
===================================================================
--- testsuite/g++.dg/parse/error54.C (revision 0)
+++ testsuite/g++.dg/parse/error54.C (working copy)
@@ -0,0 +1,19 @@
+// PR c++/51640
+
+class ex {};
+
+namespace t
+{
+ class ex2 : public ex {};
+}
+
+class ex2 : public ex {};
+
+void bar()
+{
+ using namespace t;
+
+ try {
+ } catch (ex2&) { // { dg-error "reference to 'ex2' is ambiguous" }
+ }
+}