diff options
author | Jason Merrill <jason@redhat.com> | 2009-08-10 16:47:55 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2009-08-10 16:47:55 -0400 |
commit | e8f43da6f9d34f17f3e6e4adbf42e79addb5e217 (patch) | |
tree | a4546f632af854bec30da3734e864ea5f11269f0 /gcc/cp/decl.c | |
parent | 8d1b99e26ad5c88a05c7c7ba2fbb05bdc345e9d2 (diff) | |
download | gcc-e8f43da6f9d34f17f3e6e4adbf42e79addb5e217.zip gcc-e8f43da6f9d34f17f3e6e4adbf42e79addb5e217.tar.gz gcc-e8f43da6f9d34f17f3e6e4adbf42e79addb5e217.tar.bz2 |
Implement DR 757...
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.
From-SVN: r150634
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 67 |
1 files changed, 7 insertions, 60 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index be1b5b7..898542f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6747,36 +6747,6 @@ grokfndecl (tree ctype, || decl_function_context (TYPE_MAIN_DECL (ctype)))) publicp = 0; - if (publicp) - { - /* [basic.link]: A name with no linkage (notably, the name of a class - or enumeration declared in a local scope) shall not be used to - declare an entity with linkage. - - Only check this for public decls for now. See core 319, 389. */ - t = no_linkage_check (TREE_TYPE (decl), - /*relaxed_p=*/false); - if (t) - { - if (TYPE_ANONYMOUS_P (t)) - { - if (DECL_EXTERN_C_P (decl)) - /* Allow this; it's pretty common in C. */; - else - { - permerror (input_location, "non-local function %q#D uses anonymous type", - decl); - if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) - permerror (input_location, "%q+#D does not refer to the unqualified " - "type, so it is not used for linkage", - TYPE_NAME (t)); - } - } - else - permerror (input_location, "non-local function %q#D uses local type %qT", decl, t); - } - } - TREE_PUBLIC (decl) = publicp; if (! publicp) { @@ -7021,36 +6991,13 @@ grokvardecl (tree type, if (TREE_PUBLIC (decl)) { - /* [basic.link]: A name with no linkage (notably, the name of a class - or enumeration declared in a local scope) shall not be used to - declare an entity with linkage. - - Only check this for public decls for now. */ - tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false); - if (t) - { - if (TYPE_ANONYMOUS_P (t)) - { - if (DECL_EXTERN_C_P (decl)) - /* Allow this; it's pretty common in C. */ - ; - else - { - /* DRs 132, 319 and 389 seem to indicate types with - no linkage can only be used to declare extern "C" - entities. Since it's not always an error in the - ISO C++ 90 Standard, we only issue a warning. */ - warning (0, "non-local variable %q#D uses anonymous type", - decl); - if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) - warning (0, "%q+#D does not refer to the unqualified " - "type, so it is not used for linkage", - TYPE_NAME (t)); - } - } - else - warning (0, "non-local variable %q#D uses local type %qT", decl, t); - } + /* If the type of the decl has no linkage, make sure that we'll + notice that in mark_used. */ + if (DECL_LANG_SPECIFIC (decl) == NULL + && TREE_PUBLIC (decl) + && !DECL_EXTERN_C_P (decl) + && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false)) + retrofit_lang_decl (decl); } else DECL_INTERFACE_KNOWN (decl) = 1; |