Error, if compiled with -O3 (gettext)

H

Herbert Straub

What could be wrong with this simple test program:

#include <string>
#include <iostream>

class foo
{
std::string s;
public:
foo (const char *a) : s(a) {};

std::string gettext (void) { return s; }
};

int main (int argc, char **argv)
{
foo f("test");
std::string a;

a=f.gettext();

std::cout << "Test: " << a << std::endl;

return 0;
}

Compiled and linked with:
g++ -o t1 t1.cxx
../t1
Test: test

And now with -O3:
g++ -O3 -o t1 t1.cxx
t1.cxx:11: error: parse error before `,' token
t1.cxx:11: error: variable declaration is not allowed here
t1.cxx:11: error: syntax error before `{' token
t1.cxx:12: error: parse error before `}' token
t1.cxx: In function `int main(int, char**)':
t1.cxx:19: error: parse error before `,' token
t1.cxx:19: error: `dcgettext' undeclared (first use this function)
t1.cxx:19: error: (Each undeclared identifier is reported only once for
each
function it appears in.)

g++ -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared
--with-system-zlib --enable-nls --without-included-gettext
--enable-__cxa_atexit --enable-clocale=gnu --enable-debug
--enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian 20040401)

And now the old compiler 2.95:
g++-2.95 -O3 -o t1 t1.cxx
../t1
Test: test

g++-2.95 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)


Thanks, Herbert
 
M

Martin Dickopp

Herbert Straub said:
What could be wrong with this simple test program:

#include <string>
#include <iostream>

class foo
{
std::string s;
public:
foo (const char *a) : s(a) {};

The semicolon after the body of the constructor should be removed, but
that is not the cause of the trouble.
std::string gettext (void) { return s; }
};

int main (int argc, char **argv)
{
foo f("test");
std::string a;

a=f.gettext();

std::cout << "Test: " << a << std::endl;

return 0;
}

Compiled and linked with:
g++ -o t1 t1.cxx
./t1
Test: test

And now with -O3:
g++ -O3 -o t1 t1.cxx
t1.cxx:11: error: parse error before `,' token
t1.cxx:11: error: variable declaration is not allowed here
t1.cxx:11: error: syntax error before `{' token
t1.cxx:12: error: parse error before `}' token
t1.cxx: In function `int main(int, char**)':
t1.cxx:19: error: parse error before `,' token
t1.cxx:19: error: `dcgettext' undeclared (first use this function)
t1.cxx:19: error: (Each undeclared identifier is reported only once for
each
function it appears in.)

Some header defines `gettext' as a macro.

The fact that this also happens when the compiler is invoked in standard
compliant mode (g++ -O3 -std=c++98 -pedantic -o t1 t1.cxx) is a compiler
bug. You should report it; please follow the instructions on how to
report bugs at <http://gcc.gnu.org/>.

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top