name-lookup.c (169690) | name-lookup.c (220150) |
---|---|
1/* Definitions for C++ name lookup routines. 2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by --- 2910 unchanged lines hidden (view full) --- 2919 if (at_namespace_scope_p ()) 2920 error ("explicit qualification in declaration of %qD", 2921 decl); 2922 return; 2923 } 2924 2925 /* See whether this has been declared in the namespace. */ 2926 old = lookup_qualified_name (scope, DECL_NAME (decl), false, true); | 1/* Definitions for C++ name lookup routines. 2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by --- 2910 unchanged lines hidden (view full) --- 2919 if (at_namespace_scope_p ()) 2920 error ("explicit qualification in declaration of %qD", 2921 decl); 2922 return; 2923 } 2924 2925 /* See whether this has been declared in the namespace. */ 2926 old = lookup_qualified_name (scope, DECL_NAME (decl), false, true); |
2927 if (!old) | 2927 if (old == error_mark_node) |
2928 /* No old declaration at all. */ 2929 goto complain; 2930 if (!is_overloaded_fn (decl)) 2931 /* Don't compare non-function decls with decls_match here, since 2932 it can't check for the correct constness at this 2933 point. pushdecl will find those errors later. */ 2934 return; 2935 /* Since decl is a function, old should contain a function decl. */ --- 1055 unchanged lines hidden (view full) --- 3991 else if ((flags & LOOKUP_PREFER_TYPES) 3992 && qualify_lookup (iter->type, flags)) 3993 binding = iter->type; 3994 else 3995 binding = NULL_TREE; 3996 3997 if (binding) 3998 { | 2928 /* No old declaration at all. */ 2929 goto complain; 2930 if (!is_overloaded_fn (decl)) 2931 /* Don't compare non-function decls with decls_match here, since 2932 it can't check for the correct constness at this 2933 point. pushdecl will find those errors later. */ 2934 return; 2935 /* Since decl is a function, old should contain a function decl. */ --- 1055 unchanged lines hidden (view full) --- 3991 else if ((flags & LOOKUP_PREFER_TYPES) 3992 && qualify_lookup (iter->type, flags)) 3993 binding = iter->type; 3994 else 3995 binding = NULL_TREE; 3996 3997 if (binding) 3998 { |
3999 /* Only namespace-scope bindings can be hidden. */ 4000 gcc_assert (!hidden_name_p (binding)); | 3999 if (hidden_name_p (binding)) 4000 { 4001 /* A non namespace-scope binding can only be hidden if 4002 we are in a local class, due to friend declarations. 4003 In particular, consider: 4004 4005 void f() { 4006 struct A { 4007 friend struct B; 4008 void g() { B* b; } // error: B is hidden 4009 } 4010 struct B {}; 4011 } 4012 4013 The standard says that "B" is a local class in "f" 4014 (but not nested within "A") -- but that name lookup 4015 for "B" does not find this declaration until it is 4016 declared directly with "f". 4017 4018 In particular: 4019 4020 [class.friend] 4021 4022 If a friend declaration appears in a local class and 4023 the name specified is an unqualified name, a prior 4024 declaration is looked up without considering scopes 4025 that are outside the innermost enclosing non-class 4026 scope. For a friend class declaration, if there is no 4027 prior declaration, the class that is specified 4028 belongs to the innermost enclosing non-class scope, 4029 but if it is subsequently referenced, its name is not 4030 found by name lookup until a matching declaration is 4031 provided in the innermost enclosing nonclass scope. 4032 */ 4033 gcc_assert (current_class_type && 4034 LOCAL_CLASS_P (current_class_type)); 4035 4036 /* This binding comes from a friend declaration in the local 4037 class. The standard (11.4.8) states that the lookup can 4038 only succeed if there is a non-hidden declaration in the 4039 current scope, which is not the case here. */ 4040 POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE); 4041 } |
4001 val = binding; 4002 break; 4003 } 4004 } 4005 4006 /* Now lookup in namespace scopes. */ 4007 if (!val) 4008 val = unqualified_namespace_lookup (name, flags); --- 1147 unchanged lines hidden --- | 4042 val = binding; 4043 break; 4044 } 4045 } 4046 4047 /* Now lookup in namespace scopes. */ 4048 if (!val) 4049 val = unqualified_namespace_lookup (name, flags); --- 1147 unchanged lines hidden --- |