This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/10591] New: Print shows nonsenses for templated structs passed as function parameters (Linux, c++)


Description:
------------
If templated struct containing specialized constructors is passed as a function 
parameter, print command in gdb shows wrong values of it's members inside this 
function.


Testcase:
---------
template <class T>
struct TestStruct{
	T x;
	TestStruct(T x) : x(x){}
	TestStruct(const TestStruct<int>& pt) : x((T)pt.x) {}
};

void somefunction(TestStruct<int> p){
	TestStruct<double> pt(p);
	pt.x=pt.x/10.0;
}

int main(){
	TestStruct<int> p(10);
	somefunction(p);
	return 0;
}


How to reproduce:
-----------------
Compile the above mentioned testcase (g++-4.3 -ggdb -o /tmp/test /tmp/test.cpp)
and run in gdb (gdb /tmp/test) like this:

(gdb) break somefunction(TestStruct<int>) 
Breakpoint 1 at 0x80483ea: file /tmp/test.cpp, line 9.
(gdb) run
Starting program: /tmp/test 

Breakpoint 1, somefunction (p={x = -1074851108})
    at /tmp/test.cpp:9
9		TestStruct<double> pt(p);
(gdb) print p
$1 = {x = -1074851108}
(gdb) next
10		pt.x=pt.x/10.0;
(gdb) print p
$2 = {x = -1074851108}

Expected result is {x = 10}.


Environment:
------------
jd@jdl~: gdb -v
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
jd@jdl~: uname -a
Linux jdl1 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 18:40:08 UTC 2009 i686 
GNU/Linux
jd@jdl~: g++-4.3 -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' -
-with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-
languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-
system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-
threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --
program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-
gc --enable-mpfr --enable-targets=all --with-tune=generic --enable-
checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-
linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)

-- 
           Summary: Print shows nonsenses for templated structs passed as
                    function parameters (Linux, c++)
           Product: gdb
           Version: 6.8
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: dolik dot rce at seznam dot cz
                CC: gdb-prs at sourceware dot org


http://sourceware.org/bugzilla/show_bug.cgi?id=10591

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]