GCC bug when using typeof
Hi, I tried to compile the following program, but I got the following error. Is it a bug of GCC? Has it been fixed in a newer version GCC? g++ -Wall -W -pedantic -g -c -o main-g.o main.cc main.cc:57: internal compiler error: in write_type, at cp/mangle.c:1651 Please submit a full bug report, with preprocessed source if appropriate. See http://gcc.gnu.org/bugs.html> for instructions. For Debian GNU/Linux specific bug reporting instructions, see . Preprocessed source stored into /tmp/ccEcnj4W.out file, please attach this to your bugreport. Currently, I'm using g++ of the following version. g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) 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. Thanks, Peng #include namespace A { template class X { public: X() { } X(T t) : _t(t) { } const T &the_t() const { return _t; } private: T _t; }; template struct multiply_traits; template struct multiply_traits, T2> { typedef X result_type; }; template typename multiply_traits, T2>::result_type operator*(const X &x, const T2 &t) { return X(x.the_t() * t); } } namespace B { template class Y { public: Y(T t) : _t(t) { } const T &the_t() const { return _t; } private: T _t; }; template Y operator*(const Y &y, const T2 &t) { return Y(y.the_t() * t); } } int main () { A::X x(2); B::Y > y(x); std::cout << (x * 3).the_t() << std::endl; std::cout << (y * 5).the_t().the_t() << std::endl; }
Re: GCC bug when using typeof
On Mon, Oct 20, 2008 at 9:09 PM, Andrew Pinski <[EMAIL PROTECTED]> wrote: > On Mon, Oct 20, 2008 at 7:04 PM, Peng Yu <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I tried to compile the following program, but I got the following >> error. Is it a bug of GCC? Has it been fixed in a newer version GCC? >> > > It is a bug in GCC but in later versions 4.3.0 and above, we get a > sorry message: > t.cc: In instantiation of 'B::Y<__typeof__ ((T1() * T2()))> > B::operator*(const B::Y&, const T2&) [with T1 = A::X, T2 = > int]': > t.cc:54: instantiated from here > t.cc:46: sorry, unimplemented: mangling typeof, use decltype instead > > Replacing typeof with __decltype (or decltype in c++0x/g++0x modes) > works in 4.3.0 and above. Hi, Could you please help explain what the difference between typeof and decltype are? What are c++0x/g++0x modes? Thanks, Peng
Re: GCC bug when using typeof
On Mon, Oct 20, 2008 at 9:09 PM, Andrew Pinski <[EMAIL PROTECTED]> wrote: > On Mon, Oct 20, 2008 at 7:04 PM, Peng Yu <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I tried to compile the following program, but I got the following >> error. Is it a bug of GCC? Has it been fixed in a newer version GCC? >> > > It is a bug in GCC but in later versions 4.3.0 and above, we get a > sorry message: > t.cc: In instantiation of 'B::Y<__typeof__ ((T1() * T2()))> > B::operator*(const B::Y&, const T2&) [with T1 = A::X, T2 = > int]': > t.cc:54: instantiated from here > t.cc:46: sorry, unimplemented: mangling typeof, use decltype instead > > Replacing typeof with __decltype (or decltype in c++0x/g++0x modes) > works in 4.3.0 and above. Hi, Somebody replace __decltype with typeof and try to compile, he got the following error (with 4.3.0). Do you know why? main.cc:54: sorry, unimplemented: zero-operand casts cannot be mangled due to a defect in the C++ ABI main.cc:54: sorry, unimplemented: zero-operand casts cannot be mangled due to a defect in the C++ ABI Thanks, Peng
How to find out all the calling instance of a class member function?
Hi, Suppose I have a class B in namespace A, it has several overloaded member function doit. I'm wondering how to find all the lines where there is a statement that calls one particular overloaded doit member function? Is it possible to do so from g++ command line? Or I have to modify g++ to make it be able to do so? Thanks, Peng
Why g++ does not emit any information for a local variable in a template class member function?
Hi, I have the following code. I try to print the variable temp in the constructor of A. But gdb can not do that. The error message is shown blow the C++ code. According to the people from gdb mailing list, it is because that the compiler (g++) does not generate information for such variable in the debugging mode. Is it a bug of g++. BTW, I'm using g++ of the following version $ g++ --version g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) 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. Thanks, Peng template class A { public: A(int a) { T temp = a + 1; _a = temp + 1; } private: T _a; }; int main() { A a(1); } $ gdb main GNU gdb 6.4.90-debian Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". (gdb) start Breakpoint 1 at 0x400510: file main.cc, line 13. main () at main.cc:13 13A a(1); (gdb) s A (this=0x7fff250d7080, a=1) at main.cc:5 5 T temp = a + 1; (gdb) n 6 _a = temp + 1; (gdb) p temp No symbol "temp" in current context. (gdb)
POSIX in g++
Hi, There is an options -ansi to make g++ ANSI compatible. I'm wondering if there is an option to make g++ POSIX compatible. Or g++ is already POSIX compatible without an option? Thanks, Peng
Re: POSIX in g++
On Tue, Jul 15, 2008 at 5:57 PM, Ian Lance Taylor <[EMAIL PROTECTED]> wrote: > "Peng Yu" <[EMAIL PROTECTED]> writes: > >> There is an options -ansi to make g++ ANSI compatible. I'm wondering >> if there is an option to make g++ POSIX compatible. Or g++ is already >> POSIX compatible without an option? > > POSIX itself specifies features macros which you may define to compile > your source code in a strict POSIX environment. These are > _POSIX_SOURCE and _POSIX_C_SOURCE. These affect the header files > rather than the libraries. To get a strict POSIX compiler, use those > in conjunction with -ansi or -std. > > Ian >
Re: POSIX in g++
On Tue, Jul 15, 2008 at 5:57 PM, Ian Lance Taylor <[EMAIL PROTECTED]> wrote: > "Peng Yu" <[EMAIL PROTECTED]> writes: > >> There is an options -ansi to make g++ ANSI compatible. I'm wondering >> if there is an option to make g++ POSIX compatible. Or g++ is already >> POSIX compatible without an option? > > POSIX itself specifies features macros which you may define to compile > your source code in a strict POSIX environment. These are > _POSIX_SOURCE and _POSIX_C_SOURCE. These affect the header files > rather than the libraries. To get a strict POSIX compiler, use those > in conjunction with -ansi or -std. Hi Ian, Isn't ANSI C++ a subset of POSIX C++. Why do I need to specify _POSIX_SOURCE, _POSIX_C_SOURCE and -ansi? Would you please let me know what is the difference between the option -ansi and -std? Thanks, Peng
Re: no symbol in current context problem when debug the program in gdb
On Mon, Sep 15, 2008 at 2:54 PM, Peng Yu <[EMAIL PROTECTED]> wrote: > > Hi, > > I have the following program. When I step in to test's constructor, I > would be able to print the variable three. It says > (gdb) n > 7 T three = 3; > (gdb) n > 8 std::cout << three << std::endl; > (gdb) p three > No symbol "three" in current context. > > According to gdb mailing list, this is a bug in GCC. I'm wondering if > this issue has been resolved in the later versions of GCC. > > Thanks, > Peng > > #include > > template > class test { > public: > test(const T &a) : _a(a) { > T three = 3; > std::cout << three << std::endl; > } > private: > T _a; > }; > > int main() { > test p(10); > } Can somebody take a look at this issue? As installing a new compiler takes a lot of effort, I'd like to know if this has been solved in the newer version of gcc. If this has not been solved in the newer version of gcc, can somebody put this thing in the schedule? Thanks, Peng