Discussion:
[Bug python/23545] New: gdb.Type.template_argument(n) sees arguments of aliased type
sphink at gmail dot com
2018-08-17 18:35:48 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23545

Bug ID: 23545
Summary: gdb.Type.template_argument(n) sees arguments of
aliased type
Product: gdb
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: python
Assignee: unassigned at sourceware dot org
Reporter: sphink at gmail dot com
Target Milestone: ---

Consider:

template <typename T, typename U>
struct InnerType {
T t;
U u;
};

template<typename V>
using OuterType = InnerType<int, V>;

struct Container {
OuterType<float> o;
};

int main() {
Container c;
}

First, if I do `ptype Container`, it shows the field 'o' as having type
"OuterType". I would have expected "OuterType<float>".

But I was really looking at this from the python scripting side.

gdb.lookup_type("Container")['o'].type gives a type t that stringifies to plain
"OuterType". t.template_argument(0) gives 'int', and template_argument(1) gives
'float', which are the template arguments of InnerType, not OuterType.

t.strip_typedefs().template_argument calls correctly give the InnerType values.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-08-17 18:53:14 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23545

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |tromey at sourceware dot org

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
(In reply to Steve Fink from comment #0)
Post by sphink at gmail dot com
First, if I do `ptype Container`, it shows the field 'o' as having type
"OuterType". I would have expected "OuterType<float>".
This seems to be a compiler bug.
From the DWARF:

<1><86>: Abbrev Number: 7 (DW_TAG_typedef)
<87> DW_AT_name : (indirect string, offset: 0x80): OuterType
<8b> DW_AT_decl_file : 1
<8c> DW_AT_decl_line : 8
<8d> DW_AT_decl_column : 38
<8e> DW_AT_type : <0x2d>

This is just a plain typedef with no indication it is a template instantiation.
It's a typedef for:

<1><2d>: Abbrev Number: 2 (DW_TAG_structure_type)
<2e> DW_AT_name : (indirect string, offset: 0x5a): InnerType<int,
float>
<32> DW_AT_byte_size : 8
<33> DW_AT_decl_file : 1
<34> DW_AT_decl_line : 2
<35> DW_AT_decl_column : 10
<36> DW_AT_sibling : <0x5f>
[...]
<2><50>: Abbrev Number: 4 (DW_TAG_template_type_param)
<51> DW_AT_name : T
<53> DW_AT_type : <0x5f>
<2><57>: Abbrev Number: 4 (DW_TAG_template_type_param)
<58> DW_AT_name : U
<5a> DW_AT_type : <0x66>


... which seems reasonable.
Post by sphink at gmail dot com
t.template_argument(0) gives 'int', and template_argument(1) gives 'float', which are the template arguments of InnerType, not OuterType.
template_argument strips the typedefs from t before examining it. Maybe a
questionable decision.
--
You are receiving this mail because:
You are on the CC list for the bug.
tromey at sourceware dot org
2018-08-17 18:53:43 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23545

Tom Tromey <tromey at sourceware dot org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2018-08-17
Ever confirmed|0 |1

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
BTW thanks for reducing this test case.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...