public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "nickhuang99 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/104358] New: Assignable template lambda as function parameter is incorrectly reduced to type of "int"
Date: Thu, 03 Feb 2022 01:24:01 +0000	[thread overview]
Message-ID: <bug-104358-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 104358
           Summary: Assignable template lambda as function parameter is
                    incorrectly reduced to type of "int"
           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: ---

Please see code at https://www.godbolt.org/z/o3bxxsYPK
All other compilers parses this correctly.


#include <functional>
#include <type_traits>

using namespace std;

//1. I have a callback which happens to be an assignable lambda
template<typename T>
using Lambda=decltype(+[](T){});
//  which is esstially a function pointer 
static_assert(is_same_v<Lambda<int>, void(*)(int)>);

//2. Here is my data handle function which takes a data and the callback 
template<typename T>
auto foo(T&&, Lambda<T>)->T;

//3. However, parser consider the callback as type of "int"
static_assert( ! is_same_v<decltype(&foo<int>), int(*)(int&&, void(*)(int))>);
// lambda type is always considered as "int"
static_assert(is_same_v<decltype(&foo<int>), int(*)(int&&, int)>);
static_assert(is_same_v<decltype(&foo<bool>), bool(*)(bool&&, int)>);

// this is impossible as callback CANNOT be "int"
static_assert( ! is_same_v<Lambda<int>, int>);


////////////////////////////////////////////
//4. This won't happen for a traditional function pointer
template<typename T>
using FunPtr=void(*)(T);
static_assert(is_same_v<FunPtr<int>, void(*)(int)>);

//5. let's define a similar function with callback
template<typename T>
auto bar(T&&, FunPtr<T>)->T;
// there is no way for parser to consider callback as type of "int"
static_assert(is_same_v<decltype(&bar<int>), int(*)(int&&, void(*)(int))>);

             reply	other threads:[~2022-02-03  1:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03  1:24 nickhuang99 at hotmail dot com [this message]
2022-02-03 20:14 ` [Bug c++/104358] " nickhuang99 at hotmail dot com
2022-02-05 22:46 ` nickhuang99 at hotmail dot com
2022-10-27  5:21 ` [Bug c++/104358] signature of template function with template lambda(converted to function pointer) mistakenly regards it as " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104358-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).