diff options
author | aoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-23 18:57:43 +0000 |
---|---|---|
committer | aoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-23 18:57:43 +0000 |
commit | f119c0554dad5515e6c9d7cc6224a609bc73a39b (patch) | |
tree | 5bb57455330367506d430b09ceab241ae587b4ae | |
parent | feba5c4bb38a147cf06a4e60056ae0d7bc9cb824 (diff) | |
download | ppe42-gcc-f119c0554dad5515e6c9d7cc6224a609bc73a39b.tar.gz ppe42-gcc-f119c0554dad5515e6c9d7cc6224a609bc73a39b.zip |
gcc/cp/ChangeLog:
* decl.c (grokvardecl): Don't exempt anonymous types from having
linkage for variables that have linkage other than "C".
gcc/testsuite/ChangeLog:
* g++.dg/lookup/anon2.C: Don't let access checks make it look like
the test passes.
* g++.dg/other/anon3.C: Accept a warning.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95462 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 26 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/lookup/anon2.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/other/anon3.C | 2 |
5 files changed, 26 insertions, 20 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 55b43508db7..c8b31120e3c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2005-02-23 Alexandre Oliva <aoliva@redhat.com> + + * decl.c (grokvardecl): Don't exempt anonymous types from having + linkage for variables that have linkage other than "C". + 2005-02-23 Kazu Hirata <kazu@cs.umass.edu> * cp-objcp-common.h, error.c: Update copyright. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a224efc466b..bf0fb20061c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5924,8 +5924,7 @@ grokvardecl (tree type, declare an entity with linkage. Only check this for public decls for now. */ - tree t1 = TREE_TYPE (decl); - tree t = no_linkage_check (t1, /*relaxed_p=*/false); + tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false); if (t) { if (TYPE_ANONYMOUS_P (t)) @@ -5933,29 +5932,22 @@ grokvardecl (tree type, if (DECL_EXTERN_C_P (decl)) /* Allow this; it's pretty common in C. */ ; - else if (same_type_ignoring_top_level_qualifiers_p(t1, t)) - /* This is something like "enum { a = 3 } x;", which is - well formed. The enum doesn't have "a name with no - linkage", because it has no name. See closed CWG issue - 132. - - Note that while this construct is well formed in C++03 - it is likely to become ill formed in C++0x. See open - CWG issue 389 and related issues. */ - ; else { - /* It's a typedef referring to an anonymous type. */ - pedwarn ("non-local variable %q#D uses anonymous type", + /* 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 ("non-local variable %q#D uses anonymous type", decl); if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) - cp_pedwarn_at ("%q#D does not refer to the unqualified " - "type, so it is not used for linkage", + cp_warning_at ("%q#D does not refer to the unqualified " + "type, so it is not used for linkage", TYPE_NAME (t)); } } else - pedwarn ("non-local variable %q#D uses local type %qT", decl, t); + warning ("non-local variable %q#D uses local type %qT", decl, t); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70a750a25cb..408b0c2dae8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2005-02-23 Alexandre Oliva <aoliva@redhat.com> + + * g++.dg/lookup/anon2.C: Don't let access checks make it look like + the test passes. + * g++.dg/other/anon3.C: Accept a warning. + 2005-02-23 Kazu Hirata <kazu@cs.umass.edu> * gcc.dg/pr20017.c: Fix a comment typo. diff --git a/gcc/testsuite/g++.dg/lookup/anon2.C b/gcc/testsuite/g++.dg/lookup/anon2.C index 4cd64aecb49..d556ba0034a 100644 --- a/gcc/testsuite/g++.dg/lookup/anon2.C +++ b/gcc/testsuite/g++.dg/lookup/anon2.C @@ -1,6 +1,9 @@ // { dg-do compile } // { dg-options "" } -class { int i; } a; // { dg-error "private|anonymous type" } -void foo() { a.i; } // { dg-error "context" } +// Make sure we issue a diagnostic if a type with no linkage is used +// to declare a a variable that has linkage. +struct { int i; } a; // { dg-warning "anonymous type" } + +void foo() { a.i; } diff --git a/gcc/testsuite/g++.dg/other/anon3.C b/gcc/testsuite/g++.dg/other/anon3.C index 87cbfb544cd..87116eb8901 100644 --- a/gcc/testsuite/g++.dg/other/anon3.C +++ b/gcc/testsuite/g++.dg/other/anon3.C @@ -4,4 +4,4 @@ // { dg-do compile } -enum { a = 3 } x; +enum { a = 3 } x; // { dg-warning "anonymous type" } |