]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/51640 (Misleading error if the type in the catch() is ambiguous)
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 16 May 2014 17:42:23 +0000 (17:42 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 16 May 2014 17:42:23 +0000 (17:42 +0000)
/cp
2014-05-16  Paolo Carlini  <paolo.carlini@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.carlini@oracle.com>

PR c++/51640
* g++.dg/parse/error54.C: New.

From-SVN: r210521

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error54.C [new file with mode: 0644]

index 5a13125e513db0aa3292073ca69381900ccd5f96..2714cd3e9bb897ba98d603b76a9702d354cb9cfd 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-16  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51640
+       * parser.c (cp_parser_diagnose_invalid_type_name): Early return
+       when cp_parser_lookup_name sets ambiguous_decls.
+
 2014-05-15  Jason Merrill  <jason@redhat.com>
 
        * call.c (print_conversion_rejection): Use loc consistently.
index dae4393d6e21ea5112a9f36a59048e100a7f0819..7d9f81d314f9eb4c75962d04a5177f9de7083962 100644 (file)
@@ -2880,13 +2880,21 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser,
                                      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 7254012ba3e1711c15aeef9fa8646d2b2365409b..0b1d9050532841d4822c83e77cd769cf4b23313f 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-16  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51640
+       * g++.dg/parse/error54.C: New.
+
 2014-05-16  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/60969
diff --git a/gcc/testsuite/g++.dg/parse/error54.C b/gcc/testsuite/g++.dg/parse/error54.C
new file mode 100644 (file)
index 0000000..b49c76b
--- /dev/null
@@ -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" }
+  }
+}