[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gcc bug - want to verify.




Hello all!

I believe I have discovered a bug in gcc. I was able to reproduce it on my
Linux machine at home with gcc 2.7.2.1 (running on a pentium) and with gcc
2.7.2 running on a Sparc Solaris 2.5. I'd like you to test it on other
machines and OSes if you can, before I sumbit a report on it to GNU.

The bug occurs if one declares constant arrays as C++ class members. The
compilation works fine, but the linker excepts an array with the same name
to be declared in the global scope (i.e. outside the class). The two files
that are attached to this message demonstarte it:

If you run 'gcc test.cpp' you get a linker notice that the symbol arrayOne
is undeclared.
If 'gcc -DWO_CONST test.cpp' is run, the const keyword is omitted. In that
case, the compiler notifies that ANSI C++ does not permit member variables 
to be initialized with '=' but otherwise, the program compiles and runs
fine.
Furthermore, if one types 'gcc test.cpp array_def.cpp' the program is linked
without any errors or warnings. Once initiated it considers the values
entered into the array ::arrayOne (defined in array_def.cpp) to be those of
Hello::arrayOne.

Please let me know what happened after you tried those sequences on your
computers. IMO, it has something to do with gcc's non-platform specifics and
should fail everywhere.

Thanks in advance.

	Shlomi Fish





----------------------------------------------------------------------

The American Lottery - All you need is a dollar and a dream. We will
take the dollar, but you can keep the dream.

Shlomi Fish
Faculty of Electrical Engineering
The Technion

University E-mail: shlomif@t2.technion.ac.il
Home E-mail:       shlomif@ibm.net
----------------------------------------------------------------------
#include <stdio.h>

class Hello
{
	public:
	int a, b;
	int i_array[6];

	const int ciOne = 300;
#ifndef WO_CONST
	const
#endif 
	int arrayOne[5] = {1, 2, 3, 4, 5};
	
	void PrintConst();
	void PrintConstArray();
	void PrintMember();
	void PrintMemberArray();
};


void Hello::PrintMember()
{
	printf("PrintMember(): %li\n", a);
}

void Hello::PrintMemberArray()
{
	printf("PrintMemberArray: %li\n", i_array[3]);
}

void Hello::PrintConst()
{
	printf("PrintConst(): %li\n", ciOne);
}

void Hello::PrintConstArray()
{
	printf("PrintConstArray(): %li\n", arrayOne[0]);
}

int main()
{
	Hello h;
	h.a = 100;
	h.i_array[3] = 200;
	h.PrintMember();
	h.PrintMemberArray();
	h.PrintConst();
	h.PrintConstArray();
	
	return 0;
}
int arrayOne[5] = {10,20,30,40,50};