public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vopl at bk dot ru" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/100396] [11.1 regression] The template function overload is not selected correctly
Date: Mon, 03 May 2021 16:07:32 +0000	[thread overview]
Message-ID: <bug-100396-4-vTjFolUhsg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100396-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from vopl at bk dot ru ---
Please, try this, also failed

/////////0/////////1/////////2/////////3/////////4/////////5/////////6/////////7
template<class F, class... Args> struct Checker
{
    using Some = decltype(F{}(Args{}...));
};

template<class F, class... Args> concept valid =
    requires { typename Checker<F, Args...>::Some; };

/////////0/////////1/////////2/////////3/////////4/////////5/////////6/////////7
template<class F, class... Args> auto ovr(F f, Args... args)
requires valid<F, Args...>
{
    return ovr<F, Args...>(int{}, f, args...); // a second ovr is expected to
be called, but the compiler tries to call this ovr again. Collision between
'int' and 'F' is ignored, extra Args provided to call
}

template<class F, class... Args> auto ovr(int, F f, Args... args)
{
    return f(args...);
}

/////////0/////////1/////////2/////////3/////////4/////////5/////////6/////////7
void use()
{
    ovr([]{});
}


$ g++-11.1.0 -std=c++20 -c src.cpp 
src.cpp: In instantiation of 'struct Checker<use()::<lambda()>,
use()::<lambda()> >':
src.cpp:8:25:   required by substitution of 'template<class F, class ... Args>
auto ovr(F, Args ...) requires  valid<F, Args ...> [with F = use()::<lambda()>;
Args = {use()::<lambda()>}]'
src.cpp:14:27:   required from 'auto ovr(F, Args ...) requires  valid<F, Args
...> [with F = use()::<lambda()>; Args = {}]'
src.cpp:25:8:   required from here
src.cpp:4:30: error: no match for call to '(use()::<lambda()>)
(use()::<lambda()>)'
    4 |     using Some = decltype(F{}(Args{}...));
      |                           ~~~^~~~~~~~~~~
src.cpp:4:30: note: candidate: 'void (*)()' (conversion)
src.cpp:4:30: note:   candidate expects 1 argument, 2 provided
src.cpp:25:9: note: candidate: 'use()::<lambda()>'
   25 |     ovr([]{});
      |         ^
src.cpp:25:9: note:   candidate expects 0 arguments, 1 provided

----------
IMHO, the problem is not caused by concepts, but caused by corrupted
overloading selection mechanic. Please, take a look at the collision between
argument 'int{}' and first template parameter specified as 'F'. Next, no SFINAE
expected in this case due to correct overloading, but overloading failed and
SFINAE happens. Thanks.

  parent reply	other threads:[~2021-05-03 16:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 14:41 [Bug c++/100396] New: " vopl at bk dot ru
2021-05-03 15:14 ` [Bug c++/100396] " ppalka at gcc dot gnu.org
2021-05-03 16:07 ` vopl at bk dot ru [this message]
2021-05-03 17:59 ` ppalka at gcc dot gnu.org
2021-05-04 10:08 ` vopl at bk dot ru
2021-05-04 14:29 ` [Bug c++/100396] [11 " ppalka 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-100396-4-vTjFolUhsg@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).