This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81311] New: An std::ref argument calls copy constructor instead of template constructor in C++17 mode
- From: "pdimov at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 04 Jul 2017 13:39:20 +0000
- Subject: [Bug c++/81311] New: An std::ref argument calls copy constructor instead of template constructor in C++17 mode
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81311
Bug ID: 81311
Summary: An std::ref argument calls copy constructor instead of
template constructor in C++17 mode
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pdimov at gmail dot com
Target Milestone: ---
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.)