Bug 28647 - Python pretty-printer doesn't work with std::variant containing local type
Summary: Python pretty-printer doesn't work with std::variant containing local type
Status: RESOLVED DUPLICATE of bug 11907
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 10.1
: P2 normal
Target Milestone: 15.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-04 01:53 UTC by John Doe
Modified: 2024-06-24 17:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Doe 2021-12-04 01:53:51 UTC
When I compile this program:

```
#include <variant>
#include <vector>

struct G {
    int x;
};

int main() {
    struct A {
        int x;
    };
    A a;
    std::variant<A> b {a};
    std::vector<A> c {a};
    std::variant<G> d {G {}};

    __builtin_trap();
}
```

Then run it in gdb, note that `print b` prints

```
std::variant<> [no contained value]
```

but `print d` prints

```
std::variant<G> [index 0] = {{x = 0}}
```

In the first case the print is wrong.

It's caused by `Type.template_argument` function: If this is called in the Python shell

```
>>> gdb.lookup_symbol("b")[0].type.template_argument(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: syntax error
```
Comment 1 Hannes Domani 2022-01-05 16:26:53 UTC
Is this a duplicate of PR20590?
Comment 2 Hannes Domani 2024-06-24 17:51:25 UTC
Fixed.

*** This bug has been marked as a duplicate of bug 11907 ***