diff options
author | Gabriel Dos Reis <gdr@codesourcery.com> | 2001-02-16 22:52:29 +0000 |
---|---|---|
committer | Gabriel Dos Reis <gdr@gcc.gnu.org> | 2001-02-16 22:52:29 +0000 |
commit | e8186ecfef962821183f37c7f04c15e4937acfb4 (patch) | |
tree | 245b357fb269d110d467bf44522abd95190d56e5 /gcc | |
parent | 055adbaa1e397cd584fedb5cbe1a71651a7a0232 (diff) | |
download | gcc-e8186ecfef962821183f37c7f04c15e4937acfb4.zip gcc-e8186ecfef962821183f37c7f04c15e4937acfb4.tar.gz gcc-e8186ecfef962821183f37c7f04c15e4937acfb4.tar.bz2 |
decl.c (check_tag_decl): Make sure a typedef for an anonymous class-type introduces at least a type-name.
cp/
* decl.c (check_tag_decl): Make sure a typedef for an anonymous
class-type introduces at least a type-name.
testsuite/
* g++.old-deja/g++.other/decl9.C: New test.
From-SVN: r39781
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.other/decl9.C | 9 |
4 files changed, 42 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d79146c..55f14cf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2001-02-16 Gabriel Dos Reis <gdr@codesourcery.com> + + * decl.c (check_tag_decl): Make sure a typedef for an anonymous + class-type introduces at least a type-name. + 2001-02-16 Jakub Jelinek <jakub@redhat.com> * call.c (convert_like_real): Create a temporary for non-lvalue. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3e3f37b..7cf983b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6846,6 +6846,7 @@ check_tag_decl (declspecs) { int found_type = 0; int saw_friend = 0; + int saw_typedef = 0; tree ob_modifier = NULL_TREE; register tree link; register tree t = NULL_TREE; @@ -6877,6 +6878,8 @@ check_tag_decl (declspecs) t = value; } } + else if (value == ridpointers[(int) RID_TYPEDEF]) + saw_typedef = 1; else if (value == ridpointers[(int) RID_FRIEND]) { if (current_class_type == NULL_TREE @@ -6910,6 +6913,27 @@ check_tag_decl (declspecs) && TYPE_NAME (t) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) { + /* 7/3 In a simple-declaration, the optional init-declarator-list + can be omitted only when declaring a class (clause 9) or + enumeration (7.2), that is, when the decl-specifier-seq contains + either a class-specifier, an elaborated-type-specifier with + a class-key (9.1), or an enum-specifier. In these cases and + whenever a class-specifier or enum-specifier is present in the + decl-specifier-seq, the identifiers in these specifiers are among + the names being declared by the declaration (as class-name, + enum-names, or enumerators, depending on the syntax). In such + cases, and except for the declaration of an unnamed bit-field (9.6), + the decl-specifier-seq shall introduce one or more names into the + program, or shall redeclare a name introduced by a previous + declaration. [Example: + enum { }; // ill-formed + typedef class { }; // ill-formed + --end example] */ + if (saw_typedef) + { + error ("Missing type-name in typedef-declaration."); + return NULL_TREE; + } /* Anonymous unions are objects, so they can have specifiers. */; SET_ANON_AGGR_TYPE_P (t); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3d93933..ff6cea8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-02-16 Gabriel Dos Reis <gdr@codesourcery.com> + + * g++.old-deja/g++.other/decl9.C: New test. + 2001-02-16 Jakub Jelinek <jakub@redhat.com> * g++.old-deja/g++.other/init16.C: Update the test so that it does diff --git a/gcc/testsuite/g++.old-deja/g++.other/decl9.C b/gcc/testsuite/g++.old-deja/g++.other/decl9.C new file mode 100644 index 0000000..5ec9a6e4 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/decl9.C @@ -0,0 +1,9 @@ +// Build don't link +// Origin: batali@cogsci.ucsd.edu +// Contributed by Gabriel Dos Reis <gdr@codesourcery.com> + +typedef struct { } S; // OK +typedef struct { }; // ERROR - Missing type-name + +typedef union { } U; // OK +typedef union { }; // ERROR - Missing type-name |