#! /bin/bash
#
echo "BUG REPORT:   Cygwin, g++, -O2, static member function, std::string"
echo "RUN COMMAND:  $0 $*"
echo "RESULT:       assertion \"r != 0\" failed"
echo "SIDE EFFECTS: the files ./bug0.hpp, bug1.cpp, and bug2.cpp are created."
#
cat << EOF > bug0.hpp
# include <string>
class Element {
public:
	std::string   file;

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

}; 
EOF
cat << EOF >  bug1.cpp
# 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;
}
EOF
cat << EOF > bug2.cpp
# include <cassert>
# include "bug0.hpp"
void bug2(void)
{
	Element *r = Element::root();
	Element *s = Element::root();

	assert( r != 0 );
}
EOF
echo
echo "uname -a"
uname -a
echo
echo "g++ --version"
g++ --version
echo "g++ bug1.cpp bug2.cpp -O1 -o bug"
g++ bug1.cpp bug2.cpp  -O1 -o bug
echo "./bug"
./bug
echo "g++ bug1.cpp bug2.cpp -O2 -o bug"
g++ bug1.cpp bug2.cpp  -O2 -o bug
echo "./bug"
./bug

