| 1 |
// { dg-do assemble } |
| 2 |
// g++ 1.37.1 bug 900330_01 |
| 3 |
// |
| 4 |
// As indicated by the example at the end of the section 3.5.3 of the ANSI |
| 5 |
// C standard, when a type qualifier (i.e. "const" or "volatile") is applied |
| 6 |
// to an array type, the effect should be as if the element type had been |
| 7 |
// qualified with the given qualifier. |
| 8 |
// |
| 9 |
// This rule applies to C++ also. |
| 10 |
// |
| 11 |
// In section 7.1.6 of the C++ Reference Manual it says "Each element of a |
| 12 |
// const array is const..." |
| 13 |
// |
| 14 |
// It appears however that when a name already exists for a given array type |
| 15 |
// (i.e. a typedef name) and when that name is qualified by a type qualifier, |
| 16 |
// (i.e. "const" or "volatile"), gcc & g++ may act as if the qualifier applied |
| 17 |
// to the named (array) type rather that to the elements of that type. |
| 18 |
// |
| 19 |
// The result is that (even with the -ansi and -pedantic options) g++ |
| 20 |
// generates no errors or warnings for the lines indicated (even though it |
| 21 |
// should). |
| 22 |
// |
| 23 |
// Due to the incorrect associations, gcc & g++ will also issue inappropriate |
| 24 |
// warnings in some cases (as illustrated below). |
| 25 |
|
| 26 |
// keywords: type qualifiers, arrays |
| 27 |
|
| 28 |
typedef const int const_int; |
| 29 |
typedef const_int array_of_const_int[3]; |
| 30 |
array_of_const_int *ptr_to_array_of_consts; |
| 31 |
|
| 32 |
typedef int array_of_int[3]; |
| 33 |
typedef const array_of_int const_array_of_int; |
| 34 |
const_array_of_int *ptr_to_const_array; |
| 35 |
|
| 36 |
void function_0 () |
| 37 |
{ |
| 38 |
ptr_to_array_of_consts = ptr_to_const_array; /* gets bogus warning */ |
| 39 |
ptr_to_const_array = ptr_to_array_of_consts; /* gets bogus warning */ |
| 40 |
} |
| 41 |
|
| 42 |
/* The following example is taken from ANSI 3.5.3 */ |
| 43 |
|
| 44 |
typedef int A[2][3]; |
| 45 |
const A a = {{4, 5, 6}, {7, 8, 9}}; |
| 46 |
int *pi; |
| 47 |
|
| 48 |
void function_1 () |
| 49 |
{ |
| 50 |
pi = a[0]; // { dg-error "" } a[0] has type "const int *" |
| 51 |
} |
| 52 |
|
| 53 |
int main () { return 0; } |