public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102728] New: requires statement fails to recognize lambda in unevaluated context
@ 2021-10-13 14:01 nickhuang99 at hotmail dot com
  2024-04-13  7:53 ` [Bug c++/102728] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-10-13 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102728
           Summary: requires statement fails to recognize lambda in
                    unevaluated context
           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: ---

Consider that this snippet of code gives error of no matching specialization
which is not rooted from lambda in function parameter, instead it is rooted
from "requires" statement violation of lambda in unevaluated-context. The
warning about no-return-statement in lambda within requirement exposes this is
"requires" issue.

#include <concepts>
template<class T>
concept IsLambda=requires(T t){
    {t}->std::convertible_to<decltype(+[]{})>; 
};

template<IsLambda T> // OK if replace IsLambda with "class"
void foo(T t){ t();}

template<>
void foo<decltype(+[]{})>(decltype(+[]{}) t){
    t();
}

Also, a proof that this is not lambda-in-function-parameter issue is that you
can replace template parameter "IsLambda" in template function declaration with
"class" and GCC works fine.

Both clang and MSVC++ accepts above code. (https://www.godbolt.org/z/xhW7Tofao)





<source>: In substitution of 'template<class T>  requires  IsLambda<T> void
foo(T) [with T = void (*)()]':
<source>:12:44:   required from here
<source>:5:40: warning: no return statement in function returning non-void
[-Wreturn-type]
    5 |     {t}->std::convertible_to<decltype(+[]{})>;
      |                                        ^~~~
<source>:12:6: error: template-id 'foo<void (*)()>' for 'void foo(void (*)())'
does not match any template declaration
   12 | void foo<decltype(+[]{})>(decltype(+[]{}) t){
      |      ^~~~~~~~~~~~~~~~~~~~
<source>:9:6: note: candidate is: 'template<class T>  requires  IsLambda<T>
void foo(T)'
    9 | void foo(T t){ t();}
      |      ^~~

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

* [Bug c++/102728] requires statement fails to recognize lambda in unevaluated context
  2021-10-13 14:01 [Bug c++/102728] New: requires statement fails to recognize lambda in unevaluated context nickhuang99 at hotmail dot com
@ 2024-04-13  7:53 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-13  7:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-13
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2024-04-13  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 14:01 [Bug c++/102728] New: requires statement fails to recognize lambda in unevaluated context nickhuang99 at hotmail dot com
2024-04-13  7:53 ` [Bug c++/102728] " 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).