@@ -5631,7 +5631,7 @@ extern void cxx_omp_finish_clause (tree);
extern bool cxx_omp_privatize_by_reference (const_tree);
/* in name-lookup.c */
-extern void suggest_alternatives_for (tree);
+extern void suggest_alternatives_for (location_t, tree);
/* -- end of C++ */
@@ -452,7 +452,7 @@ unqualified_name_lookup_error (tree name)
if (!objc_diagnose_private_ivar (name))
{
error ("%qD was not declared in this scope", name);
- suggest_alternatives_for (name);
+ suggest_alternatives_for (location_of (name), name);
}
/* Prevent repeated error messages by creating a VAR_DECL with
this NAME in the innermost block scope. */
@@ -3923,7 +3923,7 @@ remove_hidden_names (tree fns)
possible candidates. */
void
-suggest_alternatives_for (tree name)
+suggest_alternatives_for (location_t location, tree name)
{
VEC(tree,heap) *candidates = NULL;
VEC(tree,heap) *namespaces_to_search = NULL;
@@ -3931,7 +3931,6 @@ suggest_alternatives_for (tree name)
int n_searched = 0;
tree t;
unsigned ix;
- location_t name_location;
VEC_safe_push (tree, heap, namespaces_to_search, global_namespace);
@@ -3955,15 +3954,13 @@ suggest_alternatives_for (tree name)
VEC_safe_push (tree, heap, namespaces_to_search, t);
}
- name_location = location_of (name);
-
/* If we stopped before we could examine all namespaces, inform the
user. Do this even if we don't have any candidates, since there
might be more candidates further down that we weren't able to
find. */
if (n_searched >= max_to_search
&& !VEC_empty (tree, namespaces_to_search))
- inform (name_location,
+ inform (location,
"maximum limit of %d namespaces searched for %qE",
max_to_search, name);
@@ -3973,7 +3970,7 @@ suggest_alternatives_for (tree name)
if (VEC_empty (tree, candidates))
return;
- inform_n (name_location, VEC_length (tree, candidates),
+ inform_n (location, VEC_length (tree, candidates),
"suggested alternative:",
"suggested alternatives:");
@@ -2672,9 +2672,15 @@ qualified_name_lookup_error (tree scope, tree name,
error_at (location, "%qD is not a member of %qT", name, scope);
}
else if (scope != global_namespace)
- error_at (location, "%qD is not a member of %qD", name, scope);
+ {
+ error_at (location, "%qD is not a member of %qD", name, scope);
+ suggest_alternatives_for (location, name);
+ }
else
- error_at (location, "%<::%D%> has not been declared", name);
+ {
+ error_at (location, "%<::%D%> has not been declared", name);
+ suggest_alternatives_for (location, name);
+ }
}
/* If FNS is a member function, a set of member functions, or a
new file mode 100644
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+namespace N { namespace M { int foo; } } // { dg-message "N::M::foo" }
+int f (void) { return N::foo; } // { dg-error "not a member" }
+// { dg-message "suggested alternative" "missing namespace" { target *-*-* } 4 }
+
+int g (void) { return ::foo; } // { dg-error "not been declared" }
+// { dg-message "suggested alternative" "omitted namespace" { target *-*-* } 7 }