This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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 libstdc++/82470] New: Structured bindings don't work with std::tuple if a type has a get member function


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82470

            Bug ID: 82470
           Summary: Structured bindings don't work with std::tuple if a
                    type has a get member function
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: morwenn29 at hotmail dot fr
  Target Milestone: ---

Here is a simple example of failing code:

    struct foobar
    {
        template<std::size_t N>
        int get() { return N; }
    };

    int main()
    {
        std::tuple<int, foobar> tu;
        auto [a, b] = tu;
    }

The compiler complains about the function foobar::get being unaccessible. This
is caused by the packing behaviour of std::tuple: foobar begin an empty class,
std::tuple will attempt EBCO and eventually privately inherit from foobar.
Structured bindings first look for a get member function in std::tuple<int,
foobar>, and find foobar::get because it has the correct interface and
std::tuple inherits from foobar. However the private inheritance makes the
function inaccessible and triggers a compiler error accordingly.

I don't know whether it's possible to solve the problem while keeping the full
EBCO capabilities, save for a change in structured bindings lookup rules.

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