public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/60448] swap_ranges does not use ADL correctly
Date: Thu, 06 Mar 2014 16:27:00 -0000	[thread overview]
Message-ID: <bug-60448-4-IEuFMXpqdP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-60448-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60448

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Slightly different version of that last test:

namespace tagged
{

template <typename T>
struct Swappable {};

#ifndef NO_CUSTOM_SWAP
template <typename T>
void swap(Swappable<T> & a, Swappable<T> & b) {
   static_cast<T &>(a).swap(static_cast<T &>(b));
}
#endif

} // namespace tagged

namespace std
{
#ifdef SWAP_FIRST
  template<typename T>
    void swap(T& a, T& b);
#endif

  template<typename T>
    void swapper(T t)
    {
      swap(*t, *t);
    }

  template<typename T>
    void swap(T& a, T& b)
    {
      T tmp = static_cast<T&&>(a);
      a = static_cast<T&&>(b);
      b = static_cast<T&&>(tmp);
    }
}

int main()
{
  struct local : tagged::Swappable<local> {
    local(int x) : data(x) {}

    local(local const &) = delete;
    local(local      &&) = delete;
    local & operator=(local const &) = delete;
    local & operator=(local      &&) = delete;

    void swap(local & other) {
       auto x = other.data;
       other.data = this->data;
       this->data = x;
    }
  private:
    int data;
  };

  local l{1};
  std::swapper(&l);
}


I must be guessing something wrong about libc++'s std::swap_ranges(), because
if it was declared before std::swap() then it would never work with any type
that doesn't provide its own swap() overload, as demonstrated by compiling the
above with NO_CUSTOM_SWAP defined.

So I don't know exactly what's going on, but I'm not convinced libstdc++ is
doing anything wrong.


  parent reply	other threads:[~2014-03-06 16:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06 13:55 [Bug libstdc++/60448] New: " public at alisdairm dot net
2014-03-06 14:15 ` [Bug libstdc++/60448] " public at alisdairm dot net
2014-03-06 15:02 ` redi at gcc dot gnu.org
2014-03-06 15:28 ` redi at gcc dot gnu.org
2014-03-06 15:40 ` redi at gcc dot gnu.org
2014-03-06 16:27 ` redi at gcc dot gnu.org [this message]
2014-03-06 16:46 ` glisse at gcc dot gnu.org
2014-03-06 16:59 ` glisse at gcc dot gnu.org
2014-03-06 17:36 ` public at alisdairm dot net
2014-03-06 19:49 ` glisse at gcc dot gnu.org
2014-03-07  8:23 ` redi at gcc dot gnu.org
2014-03-07  8:34 ` public at alisdairm dot net
2014-03-07  9:12 ` redi at gcc dot gnu.org
2014-03-07 10:00 ` glisse at gcc dot gnu.org
2014-03-07 10:58 ` public at alisdairm dot net

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-60448-4-IEuFMXpqdP@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).