aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorJoseph Myers <jsm@polyomino.org.uk>2004-01-07 19:40:03 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2004-01-07 19:40:03 +0000
commit85b58ca564339627b6c5589e5dba7f5e38a3b065 (patch)
tree9b43bfe97cac142e75644c1fc150239775554e25 /gcc/c-decl.c
parent51dc0a0aad46f10e8ff7cd9fe8d8bef3b9dfe36d (diff)
downloadgcc-85b58ca564339627b6c5589e5dba7f5e38a3b065.zip
gcc-85b58ca564339627b6c5589e5dba7f5e38a3b065.tar.gz
gcc-85b58ca564339627b6c5589e5dba7f5e38a3b065.tar.bz2
re PR c/12165 (Typedef'ed variables ignore typedef's const qualifier)
PR c/12165 * c-decl.c (grokdeclarator): Take type qualifiers of typedefed array type from the array element type. testsuite: * gcc.dg/array-quals-1.c, gcc.dg/c90-idem-qual-3.c, gcc.dg/c99-idem-qual-3.c: New tests. From-SVN: r75514
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index ee2db9e..b41ed86 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1,6 +1,6 @@
/* Process declarations and variables for C compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GCC.
@@ -3349,6 +3349,7 @@ grokdeclarator (tree declarator, tree declspecs,
int array_parm_static = 0;
tree returned_attrs = NULL_TREE;
bool bitfield = width != NULL;
+ tree element_type;
if (decl_context == FUNCDEF)
funcdef_flag = 1, decl_context = NORMAL;
@@ -3694,10 +3695,19 @@ grokdeclarator (tree declarator, tree declspecs,
two ways a declaration can become qualified. One is something
like `const int i' where the `const' is explicit. Another is
something like `typedef const int CI; CI i' where the type of the
- declaration contains the `const'. */
- constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
- restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
- volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
+ declaration contains the `const'. A third possibility is that
+ there is a type qualifier on the element type of a typedefed
+ array type, in which case we should extract that qualifier so
+ that c_apply_type_quals_to_decls receives the full list of
+ qualifiers to work with (C90 is not entirely clear about whether
+ duplicate qualifiers should be diagnosed in this case, but it
+ seems most appropriate to do so). */
+ element_type = strip_array_types (type);
+ constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (element_type);
+ restrictp
+ = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (element_type);
+ volatilep
+ = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (element_type);
inlinep = !! (specbits & (1 << (int) RID_INLINE));
if (constp > 1 && ! flag_isoc99)
pedwarn ("duplicate `const'");