[Bug g++ 3.4.4 ?] g++, -O2, static member data in line functions (fwd)

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

 





I mistakenly sent this question to gcc-bugs (which I now think is ONLY intended for messages generated by your Bugzilla bug-tracking system).

I sent a bug report to cygwin@xxxxxxxxxx because I thought it was related to cygwin, instead of g++, see
	http://www.cygwin.com/ml/cygwin/2007-10/msg00507.html

The people at cygwin seem to have passed the buck onto the gcc community; see
	http://www.cygwin.com/ml/cygwin/2007-10/msg00511.html

Here is my question: Is it true that there was a bug in g++ 3.4.4 related to using static data in line functions ? (I have attached a bash shell script that demonstrates this bug to this message.)

This is very important because template classes often have static member data access functions that return data connected to each instance of a template class. These accessor functions are often short and get inlined when -O2 is used.


I am attaching the information for the bug report to this message:

Attachment: bug.sh
Description: bash shell script for running the bug test

# include <string>
class Element {
public:
	std::string   file;

	static Element *root(void)
	{	static Element r;
		return &r;
	}

}; 
# include "bug0.hpp"
extern void bug2(void);
int main(void)
{	std::string str("A");
	char c = str[0];

	Element *r = Element::root();
	bug2();

	return 0;
}
# include <cassert>
# include "bug0.hpp"
void bug2(void)
{
	Element *r = Element::root();
	Element *s = Element::root();

	assert( r != 0 );
}
BUG REPORT:   Cygwin, g++, -O2, static member function, std::string
RUN COMMAND:  ./bug.sh
RESULT:       assertion "r != 0" failed
SIDE EFFECTS: the files ./bug0.hpp, bug1.cpp, and bug2.cpp are created.

uname -a
Linux lnx-brad.apl.washington.edu 2.6.17-1.2174_FC5 #1 Tue Aug 8 15:30:55 EDT 2006 i686 i686 i386 GNU/Linux

g++ --version
g++ (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ bug1.cpp bug2.cpp -O1 -o bug
./bug
g++ bug1.cpp bug2.cpp -O2 -o bug
./bug

BUG REPORT:   Cygwin, g++, -O2, static member function, std::string
RUN COMMAND:  ./bug.sh
RESULT:       assertion "r != 0" failed
SIDE EFFECTS: the files ./bug0.hpp, bug1.cpp, and bug2.cpp are created.

uname -a
CYGWIN_NT-5.1 pc-bbell 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin

g++ --version
g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

g++ bug1.cpp bug2.cpp -O1 -o bug
./bug
g++ bug1.cpp bug2.cpp -O2 -o bug
./bug
assertion "r != 0" failed: file "bug2.cpp", line 8
     11 [sig] bug 1924 C:\cygwin\home\Brad\trash\bug.exe: *** fatal error - call
ed with threadlist_ix -1
./bug.sh: line 58:  1924 Hangup                  ./bug

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux