public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tomaszkam at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/66998] New: not_fn invocation is not SFINAE friendly
Date: Fri, 24 Jul 2015 16:15:00 -0000	[thread overview]
Message-ID: <bug-66998-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 66998
           Summary: not_fn invocation is not SFINAE friendly
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tomaszkam at gmail dot com
  Target Milestone: ---

According to the
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4529.html#func.not_fn
the following invocations not_fn(f)(args...) and !INVOKE(f, args...) (in case
when f is function object it can be simplified to !f(args)). However the in
current implementation they behavior differs in case when they are used in
SFINAE context.

For example:
#include <experimental/functional>

template<typename F, typename Arg>
auto foo1(F f, Arg arg) -> decltype(!f(arg)) { return !f(arg); }

template<typename F, typename Arg>
auto foo1(F f, Arg arg) -> decltype(!f()) { return !f(); }

template<typename F, typename Arg>
auto foo2(F f, Arg arg) -> decltype(not_fn(f)(arg)) { return not_fn(f)(arg); }

template<typename F, typename Arg>
auto foo2(F f, Arg arg) -> decltype(not_fn(f)()) { return not_fn(f)(); }

struct negator
{
    bool operator()(int) const { return false; }
    void operator()() const {}
};

int main()
{
    foo1(negator{}, 1);
//    foo2(negator{}, 1)); //Shall be equivalent to line above. Produces an
compilation error cause by instatiation error during return type deduction.
};

The problem is caused by the use of return type deduction (decltype(auto))
instead of decltype(expr) in the implementation of not_fn. Notice that such use
does not break the function precondition placed in requires clause.


             reply	other threads:[~2015-07-24 16:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-24 16:15 tomaszkam at gmail dot com [this message]
2015-07-24 16:28 ` [Bug libstdc++/66998] " redi at gcc dot gnu.org
2015-07-24 16:32 ` tomaszkam at gmail dot com
2015-09-03 14:36 ` redi at gcc dot gnu.org
2015-09-03 15:11 ` redi at gcc dot gnu.org
2015-09-03 15:12 ` redi 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-66998-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).