diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-02 02:17:41 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-11-02 02:17:41 +0000 |
commit | abbfc22dd127467ca6080b7fa8ad06b9a241cddd (patch) | |
tree | 42b0a17506b8b37f0d7d50420e1402075faa74f3 | |
parent | 02a40ab762e2f0f630c78782a177fe030d68c922 (diff) | |
download | gcc-abbfc22dd127467ca6080b7fa8ad06b9a241cddd.tar.gz |
PR c/7353 redux
cp:
* decl2.c (grokfield): Reject TYPE_DECLs with initializers.
testsuite:
* g++.dg/ext/typedef-init.C, gcc.dg/typedef-init.C:
Add some more cases.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@58737 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/typedef-init.C | 31 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/typedef-init.c | 11 |
5 files changed, 53 insertions, 11 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8b0d77465e7..ce94b3a11b8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2002-11-01 Zack Weinberg <zack@codesourcery.com> + + PR c/7353 redux + * decl2.c (grokfield): Reject TYPE_DECLs with initializers. + 2002-10-30 Jason Merrill <jason@redhat.com> PR c++/8186 @@ -21,7 +26,7 @@ PR c++/8149 * decl.c (make_typename_type): Issue errors about invalid results. - + 2002-10-30 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> Core issue 287, PR c++/7639 @@ -77,7 +82,7 @@ * pt.c (build_template_decl): Don't set it. (tsubst_decl): Likewise. * typeck.c (expand_ptrmemfunc_cst): Don't use it. - + * class.c (build_vtbl_initializer): Don't use build_vtable_entry. (build_vtable_entry): Remove. * cp-tree.h (BINFO_VIRTUALS): Expand documentation. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 9461174eb60..93b643f7bac 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -915,7 +915,13 @@ grokfield (declarator, declspecs, init, asmspec_tree, attrlist) /* friend or constructor went bad. */ return value; if (TREE_TYPE (value) == error_mark_node) - return error_mark_node; + return error_mark_node; + + if (TREE_CODE (value) == TYPE_DECL && init) + { + error ("typedef `%D' is initialized (use __typeof__ instead)", value); + init = NULL_TREE; + } /* Pass friendly classes back. */ if (TREE_CODE (value) == VOID_TYPE) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 90877e84ac1..2b88c1f85d3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-11-01 Zack Weinberg <zack@codesourcery.com> + + * g++.dg/ext/typedef-init.C, gcc.dg/typedef-init.C: + Add some more cases. + 2002-11-01 Mark Mitchell <mark@codesourcery.com> PR c++/8391 diff --git a/gcc/testsuite/g++.dg/ext/typedef-init.C b/gcc/testsuite/g++.dg/ext/typedef-init.C index 5602783b499..1b2a05db63c 100644 --- a/gcc/testsuite/g++.dg/ext/typedef-init.C +++ b/gcc/testsuite/g++.dg/ext/typedef-init.C @@ -5,10 +5,29 @@ it's been broken since GCC 3.0 (caused ICE) and we have now removed the extension. See PR c/7353. - C++ issues a warning in addition to the error, since this construct - appears to be a case of implicit int (forbidden in std. C++) until - we get to the equals sign. */ + For cases A and C, C++ issues a warning in addition to the error, + since this construct appears to be a case of implicit int + (forbidden in std. C++) until we get to the equals sign. */ -typedef A = 0; /* { dg-error "initialized" "typedef A = B" } */ - /* { dg-warning "no type" "also warns" { target *-*-* } 12 } */ -A a; /* { dg-bogus "" "no error cascade" } */ +/* Case A: just the bare name = initializer. */ + +typedef A = 0; /* { dg-error "initialized" "A" } */ + /* { dg-warning "no type" "A warns" { target *-*-* } 14 } */ +A a; /* { dg-bogus "" "A error cascade" } */ + +/* Case B: with a type also. */ + +typedef int B = 0; /* { dg-error "initialized" "B" } */ +B b; /* { dg-bogus "" "B error cascade" } */ + +/* C and D are the same as A and B, but wrapped in a structure; + field declarations go by a different code path in C++ (ick). */ + +struct S { + typedef C = 0; /* { dg-error "initialized" "C" } */ + /* { dg-warning "no type" "C warns" { target *-*-* } 27 } */ + C c; /* { dg-bogus "" "C error cascade" } */ + + typedef int D = 0; /* { dg-error "initialized" "D" } */ + D d; /* { dg-bogus "" "D error cascade" } */ +}; diff --git a/gcc/testsuite/gcc.dg/typedef-init.c b/gcc/testsuite/gcc.dg/typedef-init.c index 9cb4830b74b..52928da9a69 100644 --- a/gcc/testsuite/gcc.dg/typedef-init.c +++ b/gcc/testsuite/gcc.dg/typedef-init.c @@ -5,5 +5,12 @@ it's been broken since GCC 3.0 (caused ICE) and we have now removed the extension. See PR c/7353. */ -typedef A = 0; /* { dg-error "initialized" "typedef A = B" } */ -A a; /* { dg-bogus "" "no error cascade" } */ +/* Case A: just the bare name = initializer. */ + +typedef A = 0; /* { dg-error "initialized" "A" } */ +A a; /* { dg-bogus "" "A error cascade" } */ + +/* Case B: with a type also. */ + +typedef int B = 0; /* { dg-error "initialized" "B" } */ +B b; /* { dg-bogus "" "B error cascade" } */ |