Skip to content

Structured bindings with pair/tuple not producing references #425

@vittorioromeo

Description

@vittorioromeo

The following code:

#include <utility>

int main()
{
    std::pair<int, char> p;
  	auto [a, b] = p;
}

Produces this after being run in cppinsights:

#include <utility>

int main()
{
  std::pair<int, char> p = std::pair<int, char>();
  std::pair<int, char> __p6 = std::pair<int, char>(p);
  int a = std::get<0UL>(static_cast<std::pair<int, char> &&>(__p6));
  char b = std::get<1UL>(static_cast<std::pair<int, char> &&>(__p6));
}

I think that is incorrect. It should be:

Produces this after being run in cppinsights:

#include <utility>

int main()
{
  std::pair<int, char> p = std::pair<int, char>();
  std::pair<int, char> __p6 = std::pair<int, char>(p);
  int& a = std::get<0UL>(static_cast<std::pair<int, char> &&>(__p6));
  char& b = std::get<1UL>(static_cast<std::pair<int, char> &&>(__p6));
}

According to cppreference:

For each identifier, a variable whose type is "reference to std::tuple_element<i, E>::type" is introduced: [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions