PR gdb/28480: Improve ambiguous member detection
authorBruno Larsen <blarsen@redhat.com>
Sat, 11 Dec 2021 07:47:53 +0000 (11:47 +0400)
committerJoel Brobecker <brobecker@adacore.com>
Sat, 11 Dec 2021 07:47:53 +0000 (11:47 +0400)
commitb6fc91c70a43d96d02c065ec0a9be96f272dace6
treed716d31cf537b4e8fc7a439a074a304650650675
parent773d894825b4f52e8858e508190edc00904b8ac1
PR gdb/28480: Improve ambiguous member detection

Basic ambiguity detection assumes that when 2 fields with the same name
have the same byte offset, it must be an unambiguous request. This is not
always correct. Consider the following code:

class empty { };

class A {
public:
  [[no_unique_address]] empty e;
};

class B {
public:
  int e;
};

class C: public A, public B { };

if we tried to use c.e in code, the compiler would warn of an ambiguity,
however, since A::e does not demand an unique address, it gets the same
address (and thus byte offset) of the members, making A::e and B::e have the
same address. however, "print c.e" would fail to report the ambiguity,
and would instead print it as an empty class (first path found).

The new code solves this by checking for other found_fields that have
different m_struct_path.back() (final class that the member was found
in), despite having the same byte offset.

The testcase gdb.cp/ambiguous.exp was also changed to test for this
behavior.

gdb/ChangeLog:

        PR gdb/28480
        * valops.c (struct_field_searcher::update_result): Improve
        ambiguous member detection.

gdb/testsuite/ChangeLog:

        PR gdb/28480

        Pushed by Joel Brobecker  <brobecker@adacore.com>
        * gdb.cp/ambiguous.cc: Add code to permit ambiguous member testing.
        * gdb.cp/ambiguous.exp: Add ambiguous member test.

(cherry picked from commit a41ad3474ceacba39e11c7478154c0e553784a01)
gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/ambiguous.cc
gdb/testsuite/gdb.cp/ambiguous.exp
gdb/valops.c
This page took 0.026115 seconds and 4 git commands to generate.