[Bug c++/67796] New: Definition for custom std::swap found by ADL but not used
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67796 Bug ID: 67796 Summary: Definition for custom std::swap found by ADL but not used Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rkirchge at gmail dot com Target Milestone: --- I am trying to use ADL to find a custom implementation of swap for tuples of an reference types. I am compiling with "-std=c++14 -Wall -Wextra". Without the following definition, the compiler reports that it cannot find the function required. With the code, the compilation succeeds without warning but "ADL works" does not print. namespace std { template void swap(std::tuple lhs, std::tuple rhs) noexcept { std::cout<<"ADL works!"< tmp = lhs; lhs = rhs; rhs = tmp; } >From my tests the swap function being used when I include the above code behaves as: auto tmp = lhs; lhs = rhs; rhs = lhs; But since these are std::tuples of reference types, the temporary value created is also a tuple of reference types, so it does not work as I intend.
[Bug c++/67796] Definition for custom std::swap found by ADL but not used
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67796 --- Comment #2 from rkirchge at gmail dot com --- Thank you for the quick reply. Defining the swap overload in std does violate the standard, but it is the shortest example that reproduces the behavior I am seeing. In my code, I have defined a wrapper around std::tuple, and defined my own swap and get function in the associated namespace. I am trying to get std::sort to call my swap function to allow me to swap values stored in tuples of references. In clang my code works. In gcc if I do not include my swap(...) definition the compiler returns an error, but if I do include it it gives no error but uses some default std::swap implementation which does not work with tuples of references. My overload of get(...) is called correctly in gcc, but swap(...) is not. It will take me some time to cleanup my code, but I will post the example as requested as soon as possible.