rfg@MCC.COM (Ron Guilmette) (06/26/89)
The following code fails to elicit an error on line 31 from
G++ 1.35.0/sun3. Also, the error messages that *are* issued
are sometimes misleading because this code (obviously) involves no
"variable-size" objects.
----------------------------------------------------------------------------
// Check that a constant integer expression (which may include declared
// constant objects) cannot be used in contexts which require a static
// integer constant expression if any of the declared integer constant
// objects only have tenative declarations, and not value definitions.
//
// Cases:
// array length specifications
// bitfield length specifications
extern const int k2; // tenative declaration
const int k4; // tenative declaration
const int k8; // tenative declaration
char global_array[((k2+7)*k4)/(k8-1)]; // ERROR
struct base
{
char member_array[((k2+7)*k4)/(k8-1)]; // ERROR
unsigned int bit_field_1:k2; // ERROR
unsigned int bit_field_2:k2+k4; // ERROR
unsigned int bit_field_3:7+k4; // ERROR
unsigned int bit_field_4:7+(k4+k2); // ERROR
unsigned int bit_field_5:(3+k4); // ERROR
};
base global_base_object;
int main ()
{
base local_base_object;
char local_array[((k2+7)*k4)/(k8-1)]; // ERROR - missed
local_array[0] = 'x';
local_base_object.bit_field_5 = 0x7f;
return 0;
}
const int k4 = 4;
const int k8 = 8;
----------------------------------------------------------------------------
g++-1.35.0.0 -g -Wall -Wwrite-strings -v -S b077.C
g++ version 1.35.0
/usr/local/src/lib/sun3/g++-1.35.0.0/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -Wall -D__HAVE_68881__ -Dmc68020 b077.C /tmp/cca20716.cpp
GNU CPP version 1.35
/usr/local/src/lib/sun3/g++-1.35.0.0/gcc-cc1plus /tmp/cca20716.cpp -quiet -dumpbase b077.C -Wall -Wwrite-strings -noreg -version -G -o b077.s
GNU C++ version 1.35.0 (68k, MIT syntax) compiled by GNU C version 1.35.
b077.C:14: variable-size type declared outside of any function
b077.C:18: variable-size type declared outside of any function
b077.C:19: structure field `bit_field_1' width not an integer constant
b077.C:20: structure field `bit_field_2' width not an integer constant
b077.C:21: structure field `bit_field_3' width not an integer constant
b077.C:22: structure field `bit_field_4' width not an integer constant
b077.C:23: structure field `bit_field_5' width not an integer constant
b077 had missed error(s) as follows:
31: char local_array[((k2+7)*k4)/(k8-1)]; // ERRORrfg@MCC.COM (Ron Guilmette) (06/26/89)
The following code fails to elicit an error message on line 9
from G++ 1.35.0/sun3.
----------------------------------------------------------------------
// Check that if a constant object is declared as external, it may not
// also be initialized to a value in the same declarative statement.
//
// Cases:
// file scope
// function local scope
// block scope
extern const int global_int_const = 11; // ERROR
int j;
void fake (int i) { j = i; }
int main ()
{
extern const int local_int_const = 33; // ERROR
fake (local_int_const);
if (j)
{
extern const int block_local = 55; // ERROR
fake (block_local);
}
fake (global_int_const);
return 0;
}
-------------------------------------------------------------------------
g++-1.35.0.0 -g -Wall -Wwrite-strings -v -S b079.C
g++ version 1.35.0
/usr/local/src/lib/sun3/g++-1.35.0.0/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -Wall -D__HAVE_68881__ -Dmc68020 b079.C /tmp/cca20766.cpp
GNU CPP version 1.35
/usr/local/src/lib/sun3/g++-1.35.0.0/gcc-cc1plus /tmp/cca20766.cpp -quiet -dumpbase b079.C -Wall -Wwrite-strings -noreg -version -G -o b079.s
GNU C++ version 1.35.0 (68k, MIT syntax) compiled by GNU C version 1.35.
In function int main ():
b079.C:16: `local_int_const' has both `extern' and initializer
b079.C:21: `block_local' has both `extern' and initializer
b079 had missed error(s) as follows:
9: extern const int global_int_const = 11; // ERROR