public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102590] New: Templated operations on variables in structured binding don't work when templated functions/lambdas require type deduction
@ 2021-10-04 11:06 1997.rajatjain at gmail dot com
  2021-10-04 11:14 ` [Bug c++/102590] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: 1997.rajatjain at gmail dot com @ 2021-10-04 11:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102590
           Summary: Templated operations on variables in structured
                    binding don't work when templated functions/lambdas
                    require type deduction
           Product: gcc
           Version: 8.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 1997.rajatjain at gmail dot com
  Target Milestone: ---

Foreach loops written with a structured-binding declaration error out if any of
the captured types contains a template member-function which is used inside the
loop.

This only happens if such a loop is placed inside a templated lambda/function.

A minimal example of the above is:

struct Foo
{
    template<typename T>
    T get() const
    {
        return static_cast<T>(0);
    }
};

template<typename T>
void error_func(T elem)
{
    std::array<std::pair<int, Foo>, 1> arr;
    for(const auto& [_, val] : arr)
    {
        val.get<int>(); // Error here
    }
}

The error disappears if T is replaced with any concrete type. It also
disappears if instead of structured bindings, a tuple is used with auto type
specifier.

The above code also works if one writes:

const auto& [_, val] = arr[0];
val.get<int>();

Compilation flags: -std=c++17

Reported error:

test.cpp:19:17: error: expected primary-expression before 'int'
         val.get<int>();
                 ^~~
test.cpp:19:17: error: expected ';' before 'int'
         val.get<int>();
                 ^~~
                 ;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-05  5:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 11:06 [Bug c++/102590] New: Templated operations on variables in structured binding don't work when templated functions/lambdas require type deduction 1997.rajatjain at gmail dot com
2021-10-04 11:14 ` [Bug c++/102590] " pinskia at gcc dot gnu.org
2021-10-04 11:31 ` 1997.rajatjain at gmail dot com
2021-10-05  5:41 ` [Bug c++/102590] structured binding inside for all loop thinks it is type depedent when it is not pinskia at gcc dot gnu.org
2021-10-05  5:43 ` [Bug c++/102590] structured binding inside for all loop thinks it is type depedent when it is not (inside a template) pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).