This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/78313] [7 Regression] Misleading spelling suggestion
- From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 15 Nov 2016 16:02:31 +0000
- Subject: [Bug c++/78313] [7 Regression] Misleading spelling suggestion
- Auto-submitted: auto-generated
- References: <bug-78313-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78313
--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #0)
> +++ This bug was initially created as a clone of Bug #72774 +++
>
> // PR c++/72774
> // { dg-do compile }
>
> void baz ();
> namespace A { void foo (); }
> void bar ()
> {
> using A::foo;
> 0 ? static_cast<foo> (0) : baz; // { dg-error "does not name a type" }
> }
>
> Actually, the suggestion looks wrong:
>
> pr72774.C:9:19: error: ‘foo’ does not name a type; did you mean ‘foo’?
>
> We call lookup_name_fuzzy with kind that we want a typename, but we actually
> except for members consider even FUNCTION_DECLs/VAR_DECLs. That doesn't
> look right.
I tried fixing this with:
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 84e064d..f0205a6 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -4723,11 +4723,12 @@ consider_binding_level (tree name, best_match <tree,
tree> &bm,
cp_binding_level *lvl, bool look_within_fields,
enum lookup_name_fuzzy_kind kind)
{
+ bool want_type_p = (kind == FUZZY_LOOKUP_TYPENAME);
+
if (look_within_fields)
if (lvl->this_entity && TREE_CODE (lvl->this_entity) == RECORD_TYPE)
{
tree type = lvl->this_entity;
- bool want_type_p = (kind == FUZZY_LOOKUP_TYPENAME);
tree best_matching_field
= lookup_member_fuzzy (type, name, want_type_p);
if (best_matching_field)
@@ -4757,6 +4758,11 @@ consider_binding_level (tree name, best_match <tree,
tree> &bm,
&& DECL_ANTICIPATED (d))
continue;
+ /* Function decls are not types. */
+ if (TREE_CODE (d) == FUNCTION_DECL
+ && want_type_p)
+ continue;
+
if (DECL_NAME (d))
bm.consider (DECL_NAME (d));
}
but then I get this:
error: 'foo' does not name a type; did you mean 'bool'?
It seems better to simply not offer a suggestion for this case (I have a patch
to do this, by detecting suggestion==goal, and suppressing such a suggestion)