X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fcp%2Fname-lookup.c;h=2136df62118184e63590fef30e4675e12c73b7ee;hb=0a8b74e0c6f3137ffa21c2907164e8bc160c9fcd;hp=dc735443db251ad3e836aa88d56622f9f3bac38e;hpb=53eeaf020e2e0d8f5c20a72f697efe608a36ed24;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index dc735443db2..2136df62118 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -28,10 +28,11 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "name-lookup.h" #include "timevar.h" -#include "toplev.h" #include "diagnostic-core.h" +#include "intl.h" #include "debug.h" #include "c-family/c-pragma.h" +#include "params.h" /* The bindings for a particular name in a particular scope. */ @@ -1634,6 +1635,22 @@ getdecls (void) return current_binding_level->names; } +/* Return how many function prototypes we are currently nested inside. */ + +int +function_parm_depth (void) +{ + int level = 0; + struct cp_binding_level *b; + + for (b = current_binding_level; + b->kind == sk_function_parms; + b = b->level_chain) + ++level; + + return level; +} + /* For debugging. */ static int no_print_functions = 0; static int no_print_builtins = 0; @@ -3917,6 +3934,68 @@ remove_hidden_names (tree fns) return fns; } +/* Suggest alternatives for NAME, an IDENTIFIER_NODE for which name + lookup failed. Search through all available namespaces and print out + possible candidates. */ + +void +suggest_alternatives_for (location_t location, tree name) +{ + VEC(tree,heap) *candidates = NULL; + VEC(tree,heap) *namespaces_to_search = NULL; + int max_to_search = PARAM_VALUE (CXX_MAX_NAMESPACES_FOR_DIAGNOSTIC_HELP); + int n_searched = 0; + tree t; + unsigned ix; + + VEC_safe_push (tree, heap, namespaces_to_search, global_namespace); + + while (!VEC_empty (tree, namespaces_to_search) + && n_searched < max_to_search) + { + tree scope = VEC_pop (tree, namespaces_to_search); + struct scope_binding binding = EMPTY_SCOPE_BINDING; + struct cp_binding_level *level = NAMESPACE_LEVEL (scope); + + /* Look in this namespace. */ + qualified_lookup_using_namespace (name, scope, &binding, 0); + + n_searched++; + + if (binding.value) + VEC_safe_push (tree, heap, candidates, binding.value); + + /* Add child namespaces. */ + for (t = level->namespaces; t; t = DECL_CHAIN (t)) + VEC_safe_push (tree, heap, namespaces_to_search, t); + } + + /* 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 (location, + "maximum limit of %d namespaces searched for %qE", + max_to_search, name); + + VEC_free (tree, heap, namespaces_to_search); + + /* Nothing useful to report. */ + if (VEC_empty (tree, candidates)) + return; + + inform_n (location, VEC_length (tree, candidates), + "suggested alternative:", + "suggested alternatives:"); + + FOR_EACH_VEC_ELT (tree, candidates, ix, t) + inform (location_of (t), " %qE", t); + + VEC_free (tree, heap, candidates); +} + /* Unscoped lookup of a global: iterate over current namespaces, considering using-directives. */ @@ -4126,8 +4205,13 @@ qualified_lookup_using_namespace (tree name, tree scope, } /* Subroutine of outer_binding. - Returns TRUE if BINDING is a binding to a template parameter of SCOPE, - FALSE otherwise. */ + + Returns TRUE if BINDING is a binding to a template parameter of + SCOPE. In that case SCOPE is the scope of a primary template + parameter -- in the sense of G++, i.e, a template that has its own + template header. + + Returns FALSE otherwise. */ static bool binding_to_template_parms_of_scope_p (cxx_binding *binding, @@ -4143,6 +4227,8 @@ binding_to_template_parms_of_scope_p (cxx_binding *binding, return (scope && scope->this_entity && get_template_info (scope->this_entity) + && PRIMARY_TEMPLATE_P (TI_TEMPLATE + (get_template_info (scope->this_entity))) && parameter_of_template_p (binding_value, TI_TEMPLATE (get_template_info \ (scope->this_entity)))); @@ -4639,7 +4725,11 @@ add_function (struct arg_lookup *k, tree fn) else if (fn == k->functions) ; else - k->functions = build_overload (fn, k->functions); + { + k->functions = build_overload (fn, k->functions); + if (TREE_CODE (k->functions) == OVERLOAD) + OVL_ARG_DEPENDENT (k->functions) = true; + } return false; } @@ -5049,8 +5139,8 @@ arg_assoc (struct arg_lookup *k, tree n) } else if (TREE_CODE (n) == OVERLOAD) { - for (; n; n = OVL_CHAIN (n)) - if (arg_assoc_type (k, TREE_TYPE (OVL_FUNCTION (n)))) + for (; n; n = OVL_NEXT (n)) + if (arg_assoc_type (k, TREE_TYPE (OVL_CURRENT (n)))) return true; }