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 python/17311] New: gdb.Type.template_argument fails with variadic arguments if they are any fixed arguments


https://sourceware.org/bugzilla/show_bug.cgi?id=17311

            Bug ID: 17311
           Summary: gdb.Type.template_argument fails with variadic
                    arguments if they are any fixed arguments
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: b.r.longbons at gmail dot com

In short:
$ git clone https://gist.github.com/o11c/208348992823821354d1
(Edit the makefile to reflect which compiler versions you have to play with)
$ make
(lots of errors)

In long:
gdb won't give me the template arguments if there is a pack after other
template arguments. It works if the pack is the first/only thing.

This appears to be related to the J/I debate, since:

gcc 4.4 is good
gcc 4.6 and newer is nondeterministicly bad or good (since it emits both
symbols)
gcc -fabi-version=6 is always bad
clang is always bad

Luckily there is a workaround, at least for template classes.

Below are copies of the files that are also in the gist.
====== 8< =========
// compile with -g -O0 -std=c++0x
#include <cstdio>

// Foo seems to work fine
template<class... T>
struct Foo {};

// Bar is often buggy
template<class F, class... R>
struct Bar {};

// Baz is a workaround
template<class... T>
struct Baz;
template<class F, class... R>
struct Baz<F, R...> {};

template<class T>
void frob(const T& v, bool c)
{
    // prevent compiler from optimizing out
    if (c)
        printf("%p\n", &v);
}

int main(int argc, char **argv)
{
    frob(Foo<int, const char *>(), argc == 0);
    frob(Bar<int, const char *>(), argc == 0);
    frob(Baz<int, const char *>(), argc == 0);
}
====== 8< ======
# vim: ft=python
start
python
import sys
import traceback

error = 0
try:
    for template in ['Foo', 'Bar', 'Baz']:
        try:
            var = gdb.parse_and_eval('(%s<int, const char *> *)0' %
template).type.target()
        except Exception as e:
            error = 1
            var = e
            traceback.print_exc()
        print '%s:' % template, var
        try:
            tp0 = var.template_argument(0)
        except Exception as e:
            error = 1
            tp0 = e
            traceback.print_exc()
        print '%s.0:' % template, tp0
        try:
            tp1 = var.template_argument(1)
        except Exception as e:
            error = 1
            tp1 = e
            traceback.print_exc()
        print '%s.1:' % template, tp1
except:
    error = 1
    traceback.print_exc()
sys.exit(error)
end

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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