aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Austern <austern@apple.com>2004-09-21 17:24:44 +0000
committerMatt Austern <austern@gcc.gnu.org>2004-09-21 17:24:44 +0000
commit6bdb98d1b015ab102211519a15df964dafbad19b (patch)
treeb2e9cdb17584c9a96c270f5e1bcf17953905af86
parent34f87940b2ec98215e6b366d33d404144ecdbef5 (diff)
downloadgcc-6bdb98d1b015ab102211519a15df964dafbad19b.zip
gcc-6bdb98d1b015ab102211519a15df964dafbad19b.tar.gz
gcc-6bdb98d1b015ab102211519a15df964dafbad19b.tar.bz2
re PR c++/15049 ([DR 278/132/216/338/389/319] global variables with anonymous types are legal)
PR c++/15049 * cp/decl.c (grokvardecl): Accept declarations of global variables using anonymous types. * testsuite/g++.dg/other/anon3.C: New. From-SVN: r87814
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c20
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/anon3.C7
4 files changed, 34 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e9e6d42..4e4a4d3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-21 Matt Austern <austern@apple.com>
+
+ PR c++/15049
+ * decl.c (grokvardecl): Accept declarations of global variables
+ using anonymous types.
+
2004-09-21 Roger Sayle <roger@eyesopen.com>
PR c++/7503
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d486505..463fa60 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5931,17 +5931,29 @@ grokvardecl (tree type,
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);
+ Only check this for public decls for now. */
+ tree t1 = TREE_TYPE (decl);
+ tree t = no_linkage_check (t1, /*relaxed_p=*/false);
if (t)
{
if (TYPE_ANONYMOUS_P (t))
{
if (DECL_EXTERN_C_P (decl))
- /* Allow this; it's pretty common in C. */;
+ /* 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 `%#D' uses anonymous type",
decl);
if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c52f7ba..11d8dfc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+ 2004-09-17 Matt Austern <austern@apple.com>
+
+ PR c++/15049
+ * g++.dg/other/anon3.C: New.
+
2004-09-21 Roger Sayle <roger@eyesopen.com>
PR c++/7503
diff --git a/gcc/testsuite/g++.dg/other/anon3.C b/gcc/testsuite/g++.dg/other/anon3.C
new file mode 100644
index 0000000..87cbfb5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/anon3.C
@@ -0,0 +1,7 @@
+// pr c++/15049
+// Origin: Matt Austern <austern@apple.com>
+// Test that we can declare a global variable whose type is anonymous.
+
+// { dg-do compile }
+
+enum { a = 3 } x;