public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20
@ 2021-10-12 23:23 nickhuang99 at hotmail dot com
2021-10-12 23:33 ` [Bug c++/102721] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-10-12 23:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721
Bug ID: 102721
Summary: out-of-line member function definition fails to allow
lambda in unevaluated-context of new feature in c++20
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nickhuang99 at hotmail dot com
Target Milestone: ---
The following snippet code exposes that GCC parser doesn't comply with c++20
standard to allow lambda in unevaluated context. It seems this out-of-line
definition creates a new lambda type where lambda as operand of "decltype"
should be treated as in unevaluated context. So, it shouldn't create a new
lambda type in out-of-line definition.
Both clang and MSVC++ (https://www.godbolt.org/z/EMbb44fd8) parse this
correctly.
(with "-std=c++20")
template<class T>
struct A
{
void foo(const T){}
};
template<>
void A<decltype(+[]{})[3]>::foo(const decltype(+[]{})[3])
{}
<source>:9:6: error: ambiguating new declaration of 'void A<void (*
[3])()>::foo(void (* const*)())'
9 | void A<decltype(+[]{})[3]>::foo(const decltype(+[]{})[3])
| ^~~~~~~~~~~~~~~~~~~~~
<source>:5:10: note: old declaration 'void A<T>::foo(T) [with T = void (*
[3])()]'
5 | void foo(const T){}
| ^~~
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102721] out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20
2021-10-12 23:23 [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20 nickhuang99 at hotmail dot com
@ 2021-10-12 23:33 ` pinskia at gcc dot gnu.org
2021-10-12 23:35 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-12 23:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-10-12
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed,
Here is a better example of what is going wrong:
template<class T>
struct A
{
void foo(const T){}
};
using t = decltype(+[]{})[3];
using t1 = const decltype(+[]{})[3];
template<>
void A<t>::foo(t1)
{}
template<>
void A<decltype(+[]{})[4]>::foo(const decltype(+[]{})[4])
{}
The first template specialization is accepted but the second one is not.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102721] out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20
2021-10-12 23:23 [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20 nickhuang99 at hotmail dot com
2021-10-12 23:33 ` [Bug c++/102721] " pinskia at gcc dot gnu.org
@ 2021-10-12 23:35 ` pinskia at gcc dot gnu.org
2021-10-12 23:37 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-12 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Confirmed,
> Here is a better example of what is going wrong:
> template<class T>
> struct A
> {
> void foo(const T){}
> };
>
> using t = decltype(+[]{})[3];
> using t1 = const decltype(+[]{})[3];
>
> template<>
> void A<t>::foo(t1)
> {}
>
> template<>
> void A<decltype(+[]{})[4]>::foo(const decltype(+[]{})[4])
> {}
>
> The first template specialization is accepted but the second one is not.
Note it is not array related either:
template<>
void A<decltype(+[]{})>::foo(const decltype(+[]{}))
{}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102721] out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20
2021-10-12 23:23 [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20 nickhuang99 at hotmail dot com
2021-10-12 23:33 ` [Bug c++/102721] " pinskia at gcc dot gnu.org
2021-10-12 23:35 ` pinskia at gcc dot gnu.org
@ 2021-10-12 23:37 ` pinskia at gcc dot gnu.org
2021-10-13 8:51 ` nickhuang99 at hotmail dot com
2021-10-13 11:59 ` nickhuang99 at hotmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-12 23:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=92707
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Maybe related to PR 92707.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102721] out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20
2021-10-12 23:23 [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20 nickhuang99 at hotmail dot com
` (2 preceding siblings ...)
2021-10-12 23:37 ` pinskia at gcc dot gnu.org
@ 2021-10-13 8:51 ` nickhuang99 at hotmail dot com
2021-10-13 11:59 ` nickhuang99 at hotmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-10-13 8:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721
--- Comment #4 from qingzhe huang <nickhuang99 at hotmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Note it is not array related either:
> template<>
> void A<decltype(+[]{})>::foo(const decltype(+[]{}))
> {}
Yes, it is not array-related. But it is definitely member function issue with
out-of line definition. See this works fine:
template<class T>
void foo(const T){}
template<>
void foo<decltype(+[]{})>(const decltype(+[]{})); //declaration
template<>
void foo<decltype(+[]{})>(const decltype(+[]{}))
{}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/102721] out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20
2021-10-12 23:23 [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20 nickhuang99 at hotmail dot com
` (3 preceding siblings ...)
2021-10-13 8:51 ` nickhuang99 at hotmail dot com
@ 2021-10-13 11:59 ` nickhuang99 at hotmail dot com
4 siblings, 0 replies; 6+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-10-13 11:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102721
--- Comment #5 from qingzhe huang <nickhuang99 at hotmail dot com> ---
(In reply to qingzhe huang from comment #4)
> (In reply to Andrew Pinski from comment #2)
> > Note it is not array related either:
> > template<>
> > void A<decltype(+[]{})>::foo(const decltype(+[]{}))
> > {}
>
> Yes, it is not array-related. But it is definitely member function issue
> with out-of line definition. See this works fine:
>
> template<class T>
> void foo(const T){}
>
> template<>
> void foo<decltype(+[]{})>(const decltype(+[]{})); //declaration
>
> template<>
> void foo<decltype(+[]{})>(const decltype(+[]{}))
> {}
Also interestingly, consider these following two cases:
1. template-class-member-function:
template<class T>
struct A{
void foo(const T){}
};
template<>
void A<decltype(+[]{})>::foo(const decltype(+[]{})){}
2. class-with-template-member-function:
struct A{
template<class T>
void foo(const T){}
};
template<>
void A::foo<decltype(+[]{})>(const decltype(+[]{})){}
Only case #1 has such issue.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-10-13 11:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 23:23 [Bug c++/102721] New: out-of-line member function definition fails to allow lambda in unevaluated-context of new feature in c++20 nickhuang99 at hotmail dot com
2021-10-12 23:33 ` [Bug c++/102721] " pinskia at gcc dot gnu.org
2021-10-12 23:35 ` pinskia at gcc dot gnu.org
2021-10-12 23:37 ` pinskia at gcc dot gnu.org
2021-10-13 8:51 ` nickhuang99 at hotmail dot com
2021-10-13 11:59 ` nickhuang99 at hotmail dot com
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).