+2010-12-14 Nathan Froyd <froydnj@codesourcery.com>
+
+ PR c++/45330
+ * cp-tree.h (suggest_alternatives_for): Add location_t parameter.
+ * name-lookup.c (suggest_alternatives_for): Likewise. Adjust.
+ * lex.c (unqualified_name_lookup_error): Adjust call to it.
+ * semantics.c (qualified_name_lookup_error): Move to...
+ * error.c (qualified_name_lookup_error): ...here. Call.
+ suggest_alternatives_for.
+
2010-12-13 Jason Merrill <jason@redhat.com>
PR c++/46873
extern void maybe_warn_cpp0x (cpp0x_warn_str str);
extern bool pedwarn_cxx98 (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
extern location_t location_of (tree);
+extern void qualified_name_lookup_error (tree, tree, tree,
+ location_t);
/* in except.c */
extern void init_exception_processing (void);
extern tree finish_template_type (tree, tree, int);
extern tree finish_base_specifier (tree, tree, bool);
extern void finish_member_declaration (tree);
-extern void qualified_name_lookup_error (tree, tree, tree,
- location_t);
extern tree finish_id_expression (tree, tree, tree,
cp_id_kind *,
bool, bool, bool *,
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++ */
va_end (ap);
return report_diagnostic (&diagnostic);
}
+
+/* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
+ we found when we tried to do the lookup. LOCATION is the location of
+ the NAME identifier. */
+
+void
+qualified_name_lookup_error (tree scope, tree name,
+ tree decl, location_t location)
+{
+ if (scope == error_mark_node)
+ ; /* We already complained. */
+ else if (TYPE_P (scope))
+ {
+ if (!COMPLETE_TYPE_P (scope))
+ error_at (location, "incomplete type %qT used in nested name specifier",
+ scope);
+ else if (TREE_CODE (decl) == TREE_LIST)
+ {
+ error_at (location, "reference to %<%T::%D%> is ambiguous",
+ scope, name);
+ print_candidates (decl);
+ }
+ else
+ 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);
+ suggest_alternatives_for (location, name);
+ }
+ else
+ {
+ error_at (location, "%<::%D%> has not been declared", name);
+ suggest_alternatives_for (location, 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. */
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;
int n_searched = 0;
tree t;
unsigned ix;
- location_t name_location;
VEC_safe_push (tree, heap, namespaces_to_search, global_namespace);
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);
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:");
return result;
}
-/* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is
- what we found when we tried to do the lookup.
- LOCATION is the location of the NAME identifier;
- The location is used in the error message*/
-
-void
-qualified_name_lookup_error (tree scope, tree name,
- tree decl, location_t location)
-{
- if (scope == error_mark_node)
- ; /* We already complained. */
- else if (TYPE_P (scope))
- {
- if (!COMPLETE_TYPE_P (scope))
- error_at (location, "incomplete type %qT used in nested name specifier",
- scope);
- else if (TREE_CODE (decl) == TREE_LIST)
- {
- error_at (location, "reference to %<%T::%D%> is ambiguous",
- scope, name);
- print_candidates (decl);
- }
- else
- 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);
- else
- error_at (location, "%<::%D%> has not been declared", name);
-}
-
/* If FNS is a member function, a set of member functions, or a
template-id referring to one or more member functions, return a
BASELINK for FNS, incorporating the current access context.
+2010-12-14 Nathan Froyd <froydnj@codesourcery.com>
+
+ PR c++/45330
+ * g++.dg/lookup/suggestions1.C: New test.
+
2010-12-14 Tobias Burnus <burnus@net-b.de>
PR fortran/46937
--- /dev/null
+// { 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 }