diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-08-10 20:47:55 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-08-10 20:47:55 +0000 |
commit | 74d6b34bc5210929bf52593bd9e536acbf6e6d4e (patch) | |
tree | a4546f632af854bec30da3734e864ea5f11269f0 /gcc/cp/name-lookup.c | |
parent | b7bf3d2595470b8de52b0ccc58b04e6a4065658a (diff) | |
download | gcc-74d6b34bc5210929bf52593bd9e536acbf6e6d4e.tar.gz |
Implement DR 757: It's OK for a decl to use a type without linkage
so long as the decl is defined in the current translation unit.
* decl2.c (no_linkage_decls): New vector.
(mark_used): Add decls that use types with no linkage.
(cp_write_global_declarations): Check that they are defined.
(decl_defined_p, no_linkage_error): New fns.
* cp-tree.h (DECL_NO_LINKAGE_CHECKED): New macro.
(struct lang_decl_base): Add flag.
* decl.c (grokfndecl): Don't check type linkage.
(grokvardecl): If the type has no linkage, just make sure
DECL_LANG_SPECIFIC is set.
* pt.c (check_instantiated_arg): Don't check type linkage.
* name-lookup.c (is_local_extern): New fn.
* name-lookup.h: Declare it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@150634 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/name-lookup.c')
-rw-r--r-- | gcc/cp/name-lookup.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index c2d877907bc..feb2cf280d1 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4392,6 +4392,34 @@ lookup_name_innermost_nonclass_level (tree name) POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t); } +/* Returns true iff DECL is a block-scope extern declaration of a function + or variable. */ + +bool +is_local_extern (tree decl) +{ + cxx_binding *binding; + + /* For functions, this is easy. */ + if (TREE_CODE (decl) == FUNCTION_DECL) + return DECL_LOCAL_FUNCTION_P (decl); + + if (TREE_CODE (decl) != VAR_DECL) + return false; + if (!current_function_decl) + return false; + + /* For variables, this is not easy. We need to look at the binding stack + for the identifier to see whether the decl we have is a local. */ + for (binding = IDENTIFIER_BINDING (DECL_NAME (decl)); + binding && binding->scope->kind != sk_namespace; + binding = binding->previous) + if (binding->value == decl) + return LOCAL_BINDING_P (binding); + + return false; +} + /* Like lookup_name_innermost_nonclass_level, but for types. */ static tree |