In the following code: ``` #include <functional> #include <iostream> struct function { function() { std::cout << "function()\n"; } template<class F> function( F ) { std::cout << "function<F>(F)\n"; } function( function const& ) { std::cout << "function(function const&)\n"; } }; int main() { function f1; function f2( std::ref(f1) ); } ``` g++ 7.1 and 8 with -std=c++1z/17 call the copy constructor, whereas with -std=c++14 they call the template constructor (as do other compilers in all language modes.)
extern "C" int puts(const char*); struct function { function() { puts("function()"); } template<class F> function( F ) { puts("function<F>(F)"); } function( function const& ) { puts("function(function const&)"); } }; struct ref { ref() = default; operator function&() const; }; int main() { function f2( ref{} ); } Compiles OK with C++14, printing "function<F>(F)" but fails to link with C++17: /tmp/ccB3mFFt.o: In function `main': /tmp/ref.cc:30: undefined reference to `ref::operator function&() const' collect2: error: ld returned 1 exit status Presumably caused by the changes for guaranteed elision in C++17. Interestingly if the conversion operator is defined as deleted then it compiles OK, choosing the function<F>(F) constructor instead.
Author: jason Date: Thu Mar 22 03:53:19 2018 New Revision: 258755 URL: https://gcc.gnu.org/viewcvs?rev=258755&root=gcc&view=rev Log: PR c++/81311 - wrong C++17 overload resolution. * call.c (build_user_type_conversion_1): Remove C++17 code. (conv_binds_ref_to_prvalue): New. (build_over_call): Handle C++17 copy elision. (build_special_member_call): Only do C++17 copy elision here if the argument is already the right type. Added: trunk/gcc/testsuite/g++.dg/overload/conv-op2.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c
bug 85101 and bug 85092 started with the patch in comment 2
Fixed in GCC 8.
*** Bug 80804 has been marked as a duplicate of this bug. ***
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>: https://gcc.gnu.org/g:62ecd2b8d46aaf96caef5fa78953216629e49ebd commit r13-460-g62ecd2b8d46aaf96caef5fa78953216629e49ebd Author: Marek Polacek <polacek@redhat.com> Date: Fri May 13 19:45:03 2022 -0400 c++: Add fixed test [PR81952] This was fixed by r258755: PR c++/81311 - wrong C++17 overload resolution. PR c++/81952 gcc/testsuite/ChangeLog: * g++.dg/overload/conv-op4.C: New test.