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
* [Bug c++/102590] Templated operations on variables in structured binding don't work when templated functions/lambdas require type deduction
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 ` pinskia at gcc dot gnu.org
2021-10-04 11:31 ` 1997.rajatjain at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-04 11:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102590
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
My bet is gcc mistaken it for being a dependent type which meaning you can use
the template keyword to workaround the issue. Also gcc 8.x series is over 3
years old so this might be fixed already in a newer version of gcc.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102590] Templated operations on variables in structured binding don't work when templated functions/lambdas require type deduction
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
3 siblings, 0 replies; 5+ messages in thread
From: 1997.rajatjain at gmail dot com @ 2021-10-04 11:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102590
--- Comment #2 from Rajat Jain <1997.rajatjain at gmail dot com> ---
Yeah .template works as well. This is in the latest release too. I wasn't sure
whether I should write the oldest version that this is in (since other 8.x
releases would need a patch as well), or the latest. Let me change that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102590] structured binding inside for all loop thinks it is type depedent when it is not.
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 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05 5:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102590
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords| |rejects-valid
Summary|Templated operations on |structured binding inside
|variables in structured |for all loop thinks it is
|binding don't work when |type depedent when it is
|templated functions/lambdas |not.
|require type deduction |
Ever confirmed|0 |1
Last reconfirmed| |2021-10-05
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase (without any includes):
struct Foo
{
template<class T> T get() const { return 0; }
};
struct f
{
int t;
Foo t1;
};
template<typename T>
void error_func(T elem)
{
f arr[1];
for(const auto& [_, val] : arr)
{
val.get<int>(); // Error here
}
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102590] structured binding inside for all loop thinks it is type depedent when it is not (inside a template)
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
` (2 preceding siblings ...)
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 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-05 5:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102590
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 84469.
*** This bug has been marked as a duplicate of bug 84469 ***
^ 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).