From 8d6e459dd04ce48a04a330b97efe87acc5b8502d Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sat, 16 Feb 2002 12:13:41 +0000 Subject: [PATCH] decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs, remove incorrect comment. cp: * decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs, remove incorrect comment. Move #if 0'd code to common path. Use IMPLICIT_TYPENAME_P. Simplify & reformat ARRAY_TYPE duplication. testsuite: * g++.dg/abi/bitfield1.C: New test. * g++.dg/abi/bitfield2.C: New test. From-SVN: r49803 --- gcc/cp/ChangeLog | 8 ++++++- gcc/cp/decl.c | 26 ++++++++++----------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/abi/bitfield1.C | 34 ++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/abi/bitfield2.C | 34 ++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/abi/bitfield1.C create mode 100644 gcc/testsuite/g++.dg/abi/bitfield2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ac273b146f6..b8f762830cd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2002-02-15 Nathan Sidwell + + * decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs, + remove incorrect comment. Move #if 0'd code to common path. Use + IMPLICIT_TYPENAME_P. Simplify & reformat ARRAY_TYPE duplication. + 2002-02-13 Jason Merrill * decl.c (builtin_function): Set TREE_THIS_VOLATILE on return fns. @@ -65,7 +71,7 @@ PR c++/109 * decl.c (grokdeclarator): Allow friend declarations from - dependant types. + dependent types. * decl2.c (handle_class_head): Don't push into template parm contexts. * pt.c (push_template_decl_real): Template parm contexts are never being defined. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index ecc60836f32..697120a3091 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10073,7 +10073,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } } } - /* C++ aggregate types. */ else if (TREE_CODE (id) == TYPE_DECL) { if (type) @@ -10083,6 +10082,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) { type = TREE_TYPE (id); TREE_VALUE (spec) = type; + typedef_decl = id; } goto found; } @@ -10097,10 +10097,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) else { type = TREE_TYPE (t); -#if 0 - /* See the code below that used this. */ - decl_attr = DECL_ATTRIBUTES (id); -#endif typedef_decl = t; } } @@ -10111,6 +10107,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) found: ; } +#if 0 + /* See the code below that used this. */ + if (typedef_decl) + decl_attr = DECL_ATTRIBUTES (typedef_decl); +#endif typedef_type = type; /* No type at all: default to `int', and set DEFAULTED_INT @@ -10157,7 +10158,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) type = integer_type_node; } - if (type && TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) + if (type && IMPLICIT_TYPENAME_P (type)) { /* The implicit typename extension is deprecated and will be removed. Warn about its use now. */ @@ -11221,16 +11222,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) /* Detect the case of an array type of unspecified size which came, as such, direct from a typedef name. - We must copy the type, so that each identifier gets - a distinct type, so that each identifier's size can be - controlled separately by its own initializer. */ + We must copy the type, so that the array's domain can be + individually set by the object's initializer. */ - if (type != 0 && typedef_type != 0 - && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0 + if (type && typedef_type + && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type) && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)) - { - type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); - } + type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE); /* Detect where we're using a typedef of function type to declare a function. last_function_parms will not be set, so we must create diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 227fad4d29b..6da29708d47 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-02-15 Nathan Sidwell + + * g++.dg/abi/bitfield1.C: New test. + * g++.dg/abi/bitfield2.C: New test. + 2002-02-15 Richard Sandiford * gcc.dg/attr-nest.c: New test. diff --git a/gcc/testsuite/g++.dg/abi/bitfield1.C b/gcc/testsuite/g++.dg/abi/bitfield1.C new file mode 100644 index 00000000000..c707c85d82b --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/bitfield1.C @@ -0,0 +1,34 @@ +// { dg-do run } +// { dg-options "-ansi -pedantic-errors -funsigned-bitfields" } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 15 Dec 2001 + +typedef int Int; +typedef signed int SInt; +typedef unsigned int UInt; + +struct A +{ + SInt bitS : 1; // signed + UInt bitU : 1; // unsigned + Int bit : 1; // signedness by -f{signed,unsigned}-bitfields +}; + +int main () +{ + A a; + + a.bitS = 1; + a.bitU = 1; + a.bit = 1; + + if (a.bitS != -1) + return 1; + if (a.bitU != 1) + return 2; + if (a.bit != 1) + return 3; + + return 0; +} diff --git a/gcc/testsuite/g++.dg/abi/bitfield2.C b/gcc/testsuite/g++.dg/abi/bitfield2.C new file mode 100644 index 00000000000..d4d1d582649 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/bitfield2.C @@ -0,0 +1,34 @@ +// { dg-do run } +// { dg-options "-ansi -pedantic-errors -fsigned-bitfields" } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 15 Dec 2001 + +typedef int Int; +typedef signed int SInt; +typedef unsigned int UInt; + +struct A +{ + SInt bitS : 1; // signed + UInt bitU : 1; // unsigned + Int bit : 1; // signedness by -f{signed,unsigned}-bitfields +}; + +int main () +{ + A a; + + a.bitS = 1; + a.bitU = 1; + a.bit = 1; + + if (a.bitS != -1) + return 1; + if (a.bitU != 1) + return 2; + if (a.bit != -1) + return 3; + + return 0; +} -- 2.30.2